当前位置:网站首页>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
边栏推荐
- Open3d learning note 3 [sampling and voxelization]
- 利用Transformer来进行目标检测和语义分割
- Learn to write article format
- Find and rfind methods in string
- Global and Chinese market of recovery equipment 2022-2028: Research Report on technology, participants, trends, market size and share
- Global and Chinese markets for Salmonella typhi nucleic acid detection kits 2022-2028: Research Report on technology, participants, trends, market size and share
- 使用Matplotlib绘制图表初步
- 高中数学必修一
- Constant pointer and pointer constant
- Remplacer l'auto - attention par MLP
猜你喜欢

The internal network of the server can be accessed, but the external network cannot be accessed

Vscode下中文乱码问题

Replace convolution with full connection layer -- repmlp

Sqlyog remote connection to MySQL database under centos7 system

Carsim problem failed to start Solver: Path Id Obj (X) was set to y; Aucune valeur de correction de xxxxx?

11月24号,我们为“满月”庆祝
![[learning notes] numerical differentiation of back error propagation](/img/1c/e28e31d7cc5ccc38607c7839ccc5f0.png)
[learning notes] numerical differentiation of back error propagation

用MLP代替掉Self-Attention

用于类别增量学习的动态可扩展表征 -- DER

Programmers can only be 35? The 74 year old programmer in the United States has been programming for 57 years and has not retired
随机推荐
利用Transformer来进行目标检测和语义分割
SQL操作数据库语法
樂理基礎(簡述)
Graph Pooling 简析
Jupyter Notebook常用快捷键(在命令模式中按H也可查看)
业务架构图
How to back up the configuration before the idea when reinstalling the idea
On November 24, we celebrate the "full moon"
Cvpr19 deep stacked hierarchical multi patch network for image deblurring paper reproduction
On the back door of deep learning model
My VIM profile
Look for we media materials from four aspects to ensure your creative inspiration
MySQL优化
WCF更新服务引用报错的原因之一
[C # note] the data in DataGridView saved in WinForm is excel and CSV
学习写文章格式
深入理解JVM
Sqlyog remote connection to MySQL database under centos7 system
Sequence problem for tqdm and print
Open3D学习笔记一【初窥门径,文件读取】