当前位置:网站首页>My SQL (II)

My SQL (II)

2022-06-26 06:43:00 The code family

DDL- Database operation

One . Inquire about

1. Query all the data

SHOW DATABASES;

2. Querying the current database

SELECT DATABASE();

Two . establish

CREATE DATABASE[ IF NOT EXISTS ] Database name [DEFAULT CHARSET Character set ] [COLLATE Arrange in order ];

3、 ... and . Delete

DROP DATABASE[IF EXISTS] Database name ;

Four . Use

USE Database name ;

DDL- Table operations - Inquire about

One . Query all tables in the current database

SHOW TABLES;

Two . Query table structure

DESC Table name ;

3、 ... and . Query the table creation statement of the specified table

SHOW CREATE TABLE Table name ;

DDL- Table operations - establish

CREATE TABLE Table name (

      Field 1 Field 1 type [COMMENT Field 1 notes ],

      Field 2  Field 2 type [COMMENT Field 2 notes ],

      Field 3  Field 3 type [COMMENT Field 3 notes ],

      ……

       Field n  Field n type [COMMENT Field n notes ]

)[COMMENT Table annotation ];

Be careful :[…] Is an optional parameter , There is no comma after the last field

DDL- Table operations - data type

value type

String type

The date type

DDL- Table operations - modify

One . Add fields

ALTER TABLE Table name ADD Field name type ( length )[COMMENT notes ] [ constraint ];

Two . Change data type

ALTER TABLE Table name MODIFY Field name New data types ( length );

3、 ... and . Modify the field name and field type

ALTER TABLE Table name CHANGE Old field name new field name type ( length )[COMMENT notes ] [ constraint ];

Four . Delete field

ALTER TABLE Table name DROP Field name ;

5、 ... and . Modify the name of the table

ALTER TABLE Table name RENAME TO The new name of the table ;

DDL- Table operations - Delete

One . Delete table

DROP TABLE[IF EXISTS] Table name ;

Two . Delete the specified table , And recreate the table

TRUNCATE TABLE Table name ;

Be careful : When deleting a table , All data in the table

原网站

版权声明
本文为[The code family]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/177/202206260637154099.html