Original link: https://blog.51cto.com/4259679
DDL database
To sql statement classification
Database query language (DQL, database query language): query statement select for the table
Database definition language (DDL, database defined language): create database , drop database , create table , drop table, etc.
Database operation language (DML, database manage language) : update , insert , delete
DDL operation database:
Add database: create database library name [ character set uft8/gbk ]
Delete the specified database: drop database library name
Query the detailed information of the specified library:
1、show create database 库名;
show create database dt55-mysql;
2、show databases
3. Check which database the current user is connected to : select database();
4. Check which tables are in the specified database: show tables
DDL table operations
Add, delete, modify and check the table of DDL
Create a table :
create table table name ( field name 1 data type, field name 2 data type ...);
Drop table : drop table table name
Query :
1. Query the structure of a certain table: desc table name
2. Print the sql creation information of a certain table : show create table table name;
Modify the table :
1. Rename the existing table:
rename table old table name to new table name
rename table bank to aaa;
2. Add field information to an existing table: alter is only for table modification *****
alter table bank add gender varchar(2);
3. Delete a field in a table:
alter table bank drop gender;
4. Rename the fields in the table : alter table table name change old field name new field name new field name data type
alter table bank change aaa uname varchar(40);
5. Modify the data type length of a field:
alter table bank change unmae uname varchar(50);
6. Add a field birthdaty to the bank table
alter table bank add birthday date; #date only year, month and day
update bank set birthdat=’2020-10-10’ where id=1;
alter table bank chang birthday birthday datatime; #with year, month, day, hour, minute and second
----------------------end---------------------
Recommended reading: