当前位置:网站首页>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 .
边栏推荐
- 系统管理员需知的 16 个 iptables 使用技巧
- Jmeter-Runtime控制器
- What is cloud native? Why is cloud native technology so popular?
- 【C】 Recursive and non recursive writing of binary tree traversal
- Hcip OSPF interface network type experiment day 4
- How to choose sentinel vs. hystrix current limiting?
- Blue Bridge Cup provincial match training camp - Calculation of date
- JMeter if controller
- This should be postman, the most complete interface testing tool in the whole network
- [golang] golang implements the URLEncode URLDecode function
猜你喜欢
随机推荐
字符串——541. 反转字符串 II
如何在家中使用 SSH 和 SFTP 协议
如何从功能测试到自动化测试?
FastCGI运行原理及php-fpm参数配置
[golang] golang implements the string interception function substr
CSDN会员的魅力何在?我要他有什么用?
【Golang】golang实现简单memcache
性能测试总结(一)---基础理论篇
Fiddler抓包工具总结
JMeter runtime controller
Robot Framework官方教程(一)入门
【C】 Recursive and non recursive writing of binary tree traversal
Semaphore详解
Leetcode 112. path sum
ctfshow ThinkPHP专题 1
Simply use MySQL index
Win10 icon turns white, recovery method
Reprint of illustrations in nature, issue 3 - area map (part2-100)
什么是云原生,云原生技术为什么这么火?
This should be postman, the most complete interface testing tool in the whole network



![08 [AIO programming]](/img/a6/156cb97e653190c76f22c88b758fef.png)




