DDL operation table structure: CRUD
One, C (create) create
1, create table
create table table name(
Column name 1 data type 1,
Column name 2 data type 2,
Column name 3 data type 3,
...
Column name n data type n
);
Note span>: The last column, no need to add a comma (,)
2, copy table
< div class="Highlighter">
create table table name like the name of the copied table;
3, MySQL data type
Common data types:
Detailed data type:
Note< /strong>: timestamp: timestamp type, including year, month, day, hour, minute and second yyyy-MM-dd HH:mm:ss, if not in the future Assign a value to this field, or assign it to null, the current system time will be used by default to automatically assign the value
Second, R (Retrieve) query
1. Query all table names in a database
2, query table structure
3. View the SQL statement to create the table
show create table table name;
3. U (Update) modification
1 , Modify the table name
alter table Table name rename to new table name
2, modify the character set of the table
alter table table name character set character set name;
3, add a column
alter table table name add column name data type
4. Modify the column name type
alter table table name change column name new column name new data type;
alter table table name modify alias new data type;
5, delete column
alter table table name drop column name
Four. D (Delete) delete
1 , Delete table
2, determine whether the table exists, and then delete it after it exists
drop table if exists table name;
create table name(
Column name 1 data type 1,
Column name 2 data type 2,
Column name 3 data type 3,
...
Column name n data type n
);
create table table name like is copied The name of the table;
show tables;
desc table name;
show create table table name;
alter table rename to new Table name
alter table table name character set character set name;
alter table table name add column name data type
alter table table name change column name new column name new data type;
alter table table name modify alias new data type;
alter table table name drop column name
drop table table name; span>
drop table if exists table name;