当前位置:网站首页>Basic syntax of MySQL DDL and DML and DQL
Basic syntax of MySQL DDL and DML and DQL
2022-07-24 11:28:00 【I read Chunqiu.】
SQL Sentence classification :
One 、DDL( Data definition language )
explain : Define and manage data objects , Such as a database , Data sheets, etc .
command :create、drop、alter
Basic grammar :
Operation of the library :
Show all libraries :show database;
Create a library :create database Library name ;
Delete a library :drop database Library name ;
Use the library :use Library name ;
The operation of the table :
Look at all the tables in the library :show tables;
Build table : create table Table name (
Field name type attribute Indexes notes ,
Field name type attribute Indexes notes ,
...
Field name type attribute Indexes notes
);
View table structure :desc Table name ;
show create table Table name ;
Storage engine :ENGING=InnoDB
Modify and delete database tables :
Modify the name of the table :alter table The old name of the table rename as The new name of the table
Modify fields :alter table Table name modify Field name type attribute
alter table Table name change Old field name new field name type attribute
Add fields :alter table Table name add Field name type attribute
Delete field ( Dangerous operation ):alter table Table name drop Field name
Delete table ( Dangerous operation ):alter table Table name
Add constraints :
Add non empty constraints :alter table Table name modify test_student char(10) not null; Delete non empty constraints
Add unique constraints :alter table Table name add unique( Table field name , Field , Field , Field );
Add primary key constraint :alter table Table name add primary key( The field name of the table , Field , Field );
Add a foreign key constraint :alter table Table name add constraint N1 foreign key ( Table field name ) references Parent table ( Parent table field name );
Deletion of constraints :
Delete not null constraint :alter table Table name modify Name type ;
Delete unique constraint :alter table Table name drop index Unique constraint name ;
Delete primary key constraint :alter table Table name drop primary key;
Delete foreign key constraint :alter table Table name drop foreign key Foreign key name ;
Two 、DML( Data operation language )
explain : Used to manipulate data contained in database objects
command :insert、update、delete
Basic grammar :
Data increase :insert into Table name ( Field name , Field name ... Field name ) values( value , value ... value );
Data deletion : keyword delete, The main function is to delete the existing records in the database table , It can be modified according to the conditions .
delete from Table name where Clause
where : Conditional statements
Data modification : Keywords are update, The main function is to modify the existing records in the database table , It can be modified according to the conditions
update Table name set Field name = value , Field name = value ... where Clause
Clear the table :truncate Table name
3、 ... and 、DQL( Data query language )
explain : Used to query database data
command :select
Basic grammar :
Inquire about :select * from Table name ;
The field is aliased :select Field name as ' Field alias ', Field name as ' Field alias ' from Table name ;
duplicate removal :select distinct Field name 1, Field name 2, Field name 3... from Table name ;
Conditional query (where Clause ):select * from Table name where Conditions ;
Fuzzy query (like):select* from Table name where Field like Conditions ;
Find in a specific range :select * from Table name where Field in( value 1, value 2...);
null Value query :select * from Table name where Field is null;
Aggregate functions :count( Field ) -- Number of Statistics
avg( Field ) -- Average
sum( Field ) -- The sum of the
max( Field ) -- Maximum
min( Field ) -- minimum value
grouping :group by Field
Sort (order by ):select * from Table name order by Field name 【desc/asc】
Pagination (limit):select * from Table name limit
That's all MySql The most basic grammar , Remember and use flexibly .
边栏推荐
- [golang] golang实现截取字符串函数SubStr
- Blue Bridge Cup - binary conversion exercise
- tcp 服务端接收数据处理思路梳理,以及select: Invalid argument报错 笔记
- [golang] golang implements MD5 encryption function
- 如何从功能测试到自动化测试?
- Xilinx FPGA Microblaze AXI_ IIC usage and experience
- Talk about software testing - automated testing framework
- Classification and introduction of arm and series processors
- 使用Prometheus+Grafana实时监控服务器性能
- Fiddler packet capture tool summary
猜你喜欢

Fiddler抓包工具总结

Fiddler packet capture tool summary

JMeter if controller

E2PROM read / write (xiicps) on PS side of zcu102 board

Jmeter-Runtime控制器

Hcip OSPF interface network type experiment day 4

2022,软测人的平均薪资,看完我瞬间凉了...
![[deserialization vulnerability-01] Introduction to serialization and deserialization](/img/e4/6b9ee6ee74f3cdc3c886ed3af9ef73.png)
[deserialization vulnerability-01] Introduction to serialization and deserialization

Zynq TTC usage
![Operational amplifier - Notes on rapid recovery [II] (application)](/img/fd/e12f43e23e6ec76c2b44ce7813e204.png)
Operational amplifier - Notes on rapid recovery [II] (application)
随机推荐
How to go from functional testing to automated testing?
Leetcode 257. all paths of binary tree
Altium one key automatic BOM
Lanqiao cup provincial training camp - commonly used STL
RetinaNet:Focal Loss for Dense Object Detection
The number of digits of power and factorial
字符串——541. 反转字符串 II
Online customer service chat system source code_ Beautiful and powerful golang kernel development_ Binary operation fool installation_ Construction tutorial attached
哈希——15. 三数之和
PDF处理还收费?不可能!
Redis cluster setup
[deserialization vulnerability-02] principle test and magic method summary of PHP deserialization vulnerability
强引用、软引用、弱引用、虚引用有什么区别?
【Golang】golang实现发送微信服务号模板消息
tcp 服务端接收数据处理思路梳理,以及select: Invalid argument报错 笔记
【Golang】golang实现简单memcache
字符串——344.反转字符串
简单使用 MySQL 索引
Zynq TTC usage
[golang] golang implements the URLEncode URLDecode function