当前位置:网站首页>SQL operation database syntax
SQL operation database syntax
2022-07-02 08:10:00 【Wang Ziliang】
SQL Concept understanding and usage of
What is? SQL:
Structured Query Language: Structured query language ,
In fact, it defines the rules for operating all relational databases .
Relational database :
Reational DBMS;
SQL The general syntax of :
· SQL Statements can be written in one or more lines , It ends with a semicolon .
· You can use spaces and indents to enhance the readability of the language .
· MySql Database SQL Statement is case insensitive . It is recommended to use uppercase .
SELECT * FROM student
· Three notes W
Single-line comments : – The comment or # The comment (Mysql specific ) Multiline comment /* notes */
SQL The classification of
SQL The classification of :
1): DDL(Data Definition Language) Data definition language
Used to define database objects : database , surface , Column , etc. . keyword : caeate, drop, alter etc.
2): DML(Data Manipulation Language) Data operation language
It is used to add, delete and modify data in the database . keyword : insert, delete, update etc.
3): DQL(Data Query Language) Data query language
Used to query the records of tables in the database ( data ). keyword : select, where etc. .
4): DCL(Data Control Language) Data control language ( understand )
Used to define database access and security levels , And create users . keyword : GRANT, REVOKE etc. .
The first point DDL: Operating the database _ Create a query
DDL: Operating the database 、 surface :
1. Operating the database : CRUD
C(Create): establish R(Retrieve): Inquire about U(Update): modify D(Delete): Delete Using a database
C:
* Create database :
* create database Database name ;
* Determine whether the database exists . If it doesn't exist, I'm creating , Existence contrary .
* create database if not exists Database name ;
* Change the character set when creating the database ( Default utf-8)
* create database Database name character set Character set ;
* subject : establish db4 database , Judge whether it exists , And set the character set to gbk;
* create database if not exists db4 character set gbk;
R:
* Find the names of all databases :
* show databases;
* View the character set of the corresponding database : *( View the creation statement of a database )
* show create database mysql; SHOW CREATE DATABASE mysql; (mysql Is the corresponding database , You can change to the database you want to view .)
U:
* Modify the character set of the database :
* alter database Database name character set Character set name ;
D:
* Delete database :
* drop database Database name ;
* Judge its existence Delete if it exists . On the contrary, inaction :
* drop database if exists Database name ;
Using a database :
* Using a database
* use Database name ;
* Query the name of the database currently in use
* select database();
DDL Operation table _ Inquire about _ establish _ modify _ Delete
C(Create): establish
* create table Table name (
Name 1 data type 1,
Name 2 data type 2,
...
Name n data type n
);
*** SQL Common data types :
int Integer types ;
double Decimal type ;
double(5 ,2); // The maximum number of decimals is five , Keep two decimal places .
date The date type , The date type only includes year, month and day . yyyy-MM-dd
datetime The date type , contain Mm / DD / yyyy HHM / S yyyy-MM-dd HH:mm:ss;
timestamp Timestamp type ; contain Mm / DD / yyyy HHM / S yyyy-MM-dd HH:mm:ss;
* If you don't assign a value to this field in the future , Or assign it to null; The current system time is used by default , To automatically assign .
varchar; Character type
* name varchar(20); // The maximum character length is 20 position ;
R(Retrieve): Inquire about
* Query all table names in a database :
* show tables;
* Query table structure :
* desc Table name ;
U(Update): modify
* Modify the name of the table : alter table Table name rename to The new name of the table ;
* View the character set of the table : show create table Table name ;
* Modify the character set of the table : alter table Table name character set Character set ;
* Add a column : alter table Table name add Name data type ;
* Modify the name and type of the column : alter table Table name change Old column names New column names data type ;
* Just change the type : alter table Table name modify Name data type ;
* Delete column : alter table Table name drop Name ;
D(Delete): Delete
* Delete table :
* drop table Table name ;
* Judge whether it exists in delete ; On the contrary, inaction :
* drop tabele if exists Table name ;
Copy table : create table New table like The copied table ;
SQL Common methods ( Some are continuously updated ):
It is recommended that all statements be capitalized !
*** SQL Common data types :
int Integer types ;
double Decimal type ;
double(5 ,2); // The maximum number of decimals is five , Keep two decimal places .
date The date type , The date type only includes year, month and day . yyyy-MM-dd
datetime The date type , contain Mm / DD / yyyy HHM / S yyyy-MM-dd HH:mm:ss;
timestamp Timestamp type ; contain Mm / DD / yyyy HHM / S yyyy-MM-dd HH:mm:ss;
* If you don't assign a value to this field in the future , Or assign it to null; The current system time is used by default , To automatically assign .
varchar; Character type
* name varchar(20); // The maximum character length is 20 position ;
Create database :
create database Database name ;
* Judge whether there is . If it doesn't exist, I'm creating , Existence contrary .
* create database if not exists Database name ;
* Change the character set when creating the database ( Default utf-8)
* create database Database name character set Character set ;
Delete database :
drop database Database name ;
* Judge its existence Delete if it exists . On the contrary, inaction :
* drop database if exists Database name ;
Using a database :( It can also be said to enter the database )
* use Database name ;
* Query the name of the database currently in use
* select database();
Query all databases :
show databases; SHOW DATABASES;
View the character set of the corresponding database : *( View the creation statement of a database )
show create database mysql; SHOW CREATE DATABASE mysql; (mysql Is the corresponding database , You can change to the database you want to view .)
Modify the character set of the database :
alter database Database name character set Character set name ;
Operation of the watch ;
Copy table : create table New table like The copied table ;
C(Create): establish
* create table Table name (
Name 1 data type 1,
Name 2 data type 2,
...
Name n data type n
);
R(Retrieve): Inquire about
* Query all table names in a database :
* show tables;
* Query table structure :
* desc Table name ;
D(Delete): Delete
* Delete table :
* drop table Table name ;
* Judge whether it exists in delete ; On the contrary, inaction :
* drop tabele if exists Table name ;
U(Update): modify
* Modify the name of the table : alter table Table name rename to The new name of the table ;
* View the character set of the table : show create table Table name ;
* Modify the character set of the table : alter table Table name character set Character set ;
* Add a column : alter table Table name add Name data type ;
* Modify the name and type of the column : alter table Table name change Old column names New column names data type ;
* Just change the type : alter table Table name modify Name data type ;
* Delete column : alter table Table name drop Name ;
DML: Add or delete data in the table
边栏推荐
- Target detection for long tail distribution -- balanced group softmax
- Data reverse attack under federated learning -- gradinversion
- Summary of solving the Jetson nano installation onnx error (error: failed building wheel for onnx)
- 用全连接层替代掉卷积 -- RepMLP
- 11月24号,我们为“满月”庆祝
- 多站点高可用部署
- Replace self attention with MLP
- [learning notes] matlab self compiled image convolution function
- C语言实现XML生成解析库(XML扩展)
- Sqlyog remote connection to MySQL database under centos7 system
猜你喜欢

Principes fondamentaux de la théorie musicale (brève introduction)

【学习笔记】Matlab自编图像卷积函数

Data reverse attack under federated learning -- gradinversion

Using transformer for object detection and semantic segmentation

Remplacer l'auto - attention par MLP

Simply test the two different data transmission methods of content length and chunked

jetson nano安装tensorflow踩坑记录(scipy1.4.1)

应对长尾分布的目标检测 -- Balanced Group Softmax

Vscode下中文乱码问题

It's great to save 10000 pictures of girls
随机推荐
用于类别增量学习的动态可扩展表征 -- DER
Wang extracurricular words
包图画法注意规范
w10升级至W11系统,黑屏但鼠标与桌面快捷方式能用,如何解决
C语言的库函数
浅谈深度学习模型中的后门
install. IMG production method
Real world anti sample attack against semantic segmentation
学习写文章格式
I'll show you why you don't need to log in every time you use Taobao, jd.com, etc?
力扣方法总结:查找类
On the confrontation samples and their generation methods in deep learning
业务架构图
SQL server如何卸载干净
Animation synchronization of CarSim real-time simulation
Cvpr19 deep stacked hierarchical multi patch network for image deblurring paper reproduction
Using transformer for object detection and semantic segmentation
The internal network of the server can be accessed, but the external network cannot be accessed
Business architecture diagram
Principes fondamentaux de la théorie musicale (brève introduction)