当前位置:网站首页>Database SQL -- simulate inserting a large amount of data, importing / exporting database scripts, timestamp conversion and database basics
Database SQL -- simulate inserting a large amount of data, importing / exporting database scripts, timestamp conversion and database basics
2022-04-23 03:25:00 【Crispy hairtail in the corner of the mountain】
Take it out and encourage everyone , Please correct the shortcomings .
Study notes a long time ago , Always stored locally
List of articles
Copy existing data for filling
INSERT into test_batch(name,sex) select name,sex from test_batch
Simulate inserting large amounts of data
package cn.fon.bean;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
// Insert a large amount of data , Insert into database
public class Dbutil {
private static String url = "jdbc:mysql://127.0.0.1:3306/leave_sys?characterEncoding=utf8&useSSL=false";
private static String user = "root";
private static String pwd = "123456";
public static Connection getConn() throws Exception {
Connection conn = null;
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(url, user, pwd);
return conn;
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
public static void main(String[] args) throws Exception {
Connection conn = getConn();
Statement stmt = conn.createStatement();
for (int i = 1; i <= 20; i++) {
String sql = "insert into sys_student (id,stuID,classID,stuName,sex,address,stuTel,contact,contactTel)values(";
sql +="'"+ i + "',";
sql +="'s"+ 2018+i + "',";
sql +="'c"+ 18+i + "',";
sql +="'"+ " Zhou Qinglang "+ i+ "',";
sql +="'"+ " Woman " + "',";
sql +="'"+ " Guangzhou Changlong villa area " + "',";
sql +="'"+ i+"222222222" + "',";
sql +="'"+ " Liu Yifei "+i + "',";
sql +="'"+ i + "6666'";
sql += ")";
stmt.executeUpdate(sql);
}
}
}
The code connects to the database
public class Dbmanage {
public Connection initDB() {
Connection conn = null;
try {
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://127.0.0.1:3306/userdb?charaterEncoding=utf-8&useSSL=false";
conn = DriverManager.getConnection(url, "root", "123456");
}
catch (ClassNotFoundException e) {
e.printStackTrace();
}
catch (SQLException e) {
e.printStackTrace();
}
return conn;
}
public void closeDB(Statement sta, Connection conn) {
try {
sta.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
public void closeDB(ResultSet rs, Statement sta, Connection conn) {
try {
rs.close();
sta.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
Import database script
Create a library in the script and directly enter mysql Environmental Science :source filePath;
First of all use dbname; Select the data first
No library created , Into the mysql The environment then create database databse_name; use database database_name;source filePath;
Notice the file path filePath---- Out of commission \ Lead to Failed to open file
————————
Export database script
1、 In the left column of the tool import
Referential integrity
Defining foreign codes is mainly for the system to check the referential integrity
The value of foreign code in the reference relationship must actually exist in the referenced relationship or be null
The following actions do not undermine referential integrity :
1、 Insert .
Insert tuples into the reference relationship , To already exist in the referenced relationship
2、 Delete .
Delete a tuple in the referenced relationship , The foreign code value in the reference relationship = The primary code value of the referenced relationship , Deletion is not allowed
3、 to update .
Reference relation update , The updated foreign code value must actually exist in the referenced relationship , Only when the update is unsuccessful .
Referenced relation update , If the main code value is updated , It has no effect on the reference relationship , You can update .
Timestamp conversion
use format function
DATE_FORMAT(b.OutTime-b.InTime,"%d") %d Output by days format The function will automatically convert
Three paradigms
Three paradigms The greater the number The closer the design data sheet is to the specification
1NF
Attributes are atomic and cannot be further divided
2NF
Non primary attributes are completely functionally dependent on candidate codes —— It's all code
3NF
Non primary attributes can only be directly dependent on candidate codes —— Just code
Connect
Left connection
LEFT JOIN ( Left connection ) The left connection shows all the data in the left table , The table data on the right shows only the common part , If there is no corresponding part, you can only fill in the blank to display , The so-called left watch actually means to put it on left join The watch on the left of
A left join B
The right connection
A right join B
Full connection
OUTER JOIN( External connection 、 Full connection ) Query all the data in the left and right tables , But remove the duplicate data of the two tables The Wayne diagram is shown as follows
A outer join B
View
advantage
1). Centralize data for users , Simplify user's data query and processing .
2). Simplified operation , Shielding the complexity of the database .
3). Re customize data , Make data easy to share .
4). Merge split data , Facilitate data output to applications .
5). Simplify the management of user rights , Increase security .
Heuristic optimization
The rules 1: Perform the selection operation as early as possible .
The rules 2: Perform projection operations as early as possible .
版权声明
本文为[Crispy hairtail in the corner of the mountain]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220620064298.html
边栏推荐
- 可以接收多種數據類型參數——可變參數
- 批量下載文件----壓縮後再下載
- Problem B: small challenge
- 打卡:4.23 C语言篇 -(1)初识C语言 - (12)结构体
- Charles uses three ways to modify requests and responses
- Top ten project management software similar to JIRA
- Iotos IOT middle platform is connected to the access control system of isecure center
- 关于idea调试模式下启动特别慢的优化
- 可以接收多种数据类型参数——可变参数
- MySQL query specifies that a row is sorted to the first row
猜你喜欢
When migrating tslib_ setup: No such file or directory、ts_ open: No such file or director
Why is bi so important to enterprises?
IOTOS物联中台对接海康安防平台(iSecure Center)门禁系统
Node configuration environment CMD does not take effect
Supersocket is Use in net5 - startup
[MySQL] left function | right function
L3-011 直捣黄龙 (30 分)
Build websocket server in. Net5 webapi
全新的ORM框架——BeetlSQL介绍
《C语言程序设计》(谭浩强第五版) 第7章 用函数实现模块化程序设计 习题解析与答案
随机推荐
二进制文件版本控制工具选择难?看完这篇你会找到答案
Top 9 task management system in 2022
Translation of l1-7 matrix columns in 2022 group programming ladder Simulation Competition (20 points)
2022 团体程序设计天梯赛 模拟赛 L2-3 浪漫侧影 (25 分)
Problem a: face recognition
批量下载文件----压缩后再下载
Charles uses three ways to modify requests and responses
QT dynamic translation of Chinese and English languages
幂等性实践操作,基于业务讲解幂等性
A comprehensive understanding of static code analysis
移植tslib时ts_setup: No such file or directory、ts_open: No such file or director
. net 5 Web custom middleware implementation returns the default picture
. net webapi access authorization mechanism and process design (header token + redis)
MySQL installation pit
ThreadLocal 测试多线程变量实例
C abstract class
一文了解全面静态代码分析
Batch download of files ---- compressed and then downloaded
The query type of MySQL is very inefficient.
Xutils3 corrected a bug I reported. Happy