MySQL management-DDL statement(11)

DDL = Data Definition Language
DDL is the abbreviation of Data Definition Language . In simple terms, it is an operating language for creating, deleting, and modifying objects in the database. The biggest difference between it and the DML language is that DML only operates on the internal data of the table, and does not involve the definition of the table, the modification of the structure, and other objects. DDL statements are more commonly used by database administrators (DBAs) and seldom used by general developers.
Create a database
CREATE DATABASE dbname
MySQL management-DDL statement(11)
query the database
show databases
MySQL management-DDL statement(11)
select the database
use dbname
MySQL management-DDL statement(11)
view the table
show tables
MySQL management-DDL statement(11)
delete the database
drop database dbname
MySQL management-DDL statement(11)
create a table
create a table first create a column and then create the data in the column
CREATE TABLE table_name (column_name column_type constraints);
column_name is the name of the column
column_type is the data type
of the column. Constraints are the constraints of the column.
MySQL> create table emp(ename varchar(10), hiredate date, sal decimal(10,2), deptno int(2));
MySQL management-DDL statement(11)
add table add content
MySQL> create table dept(deptno int(3), deptname varchar(20));
Query OK, 0 rows affected (0.00 sec)
MySQL management-DDL statement(11)
MySQL> insert into dept values(5,'dept5'),(6,'dept6');
Query OK, 2 rows affected (0.00 sec)
MySQL management-DDL statement(11)
MySQL management-DDL statement(11)
View table structure
DESC tablename
MySQL management-DDL statement(11)
View table creation When the statement
show create table tablename \G;
MySQL management-DDL statement(11)
you can see information such as engine (storage engine) and charset (charset), the meaning of the \G option is to make the records arranged vertically according to the field to better display the longer content record
modify the table
modify table type
ALTER tABLE tablename mODIFY [COLUMN] column_definition [FIRST \ AFTER col_name]
MySQL management-DDL statement(11)
increase table fields
ALTER tABLE tablename ADD [COLUMN] column_definition [FIRST \ AFTER col_name]
MySQL management-DDL statement(11)
delete the table field
ALTER tABLE tablename DROP [COLUMN] col_name
MySQL management-DDL statement(11)
field Renamed
ALTER TABLE tablename CHANGE [COLUMN] old_col_name column_definition [FIRST\AFTER col_name]
MySQL management-DDL statement(11)
Both change and modify can modify the definition of the table. The difference is that the column name needs to be written twice after the change, which is inconvenient. But the advantage of change is that you can modify the column name, modify does not
modify the field sort order
ALTER TABLE tablename ADD [COLUMN] col_name [FIRST\AFTER col_name]
Add the newly added field birth date after ename,
MySQL management-DDL statement(11)
modify the field rearrangement order
ALTER TABLE tablename MODIFY [COLUMN] col_name [FIRST\AFTER col_name]
MySQL management-DDL statement(11)
Change table name
ALTER TABLE tablename RENAME[TO]new_tablename
MySQL management-DDL statement(11)
Delete table
DROP TABLE tablename
MySQL management-DDL statement(11)

Guess you like

Origin blog.51cto.com/huxiaoqiu/2540205
Recommended