DDL operation table structure

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: 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:

share picture

   Detailed data type:

share picture

share picture

  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

show tables;

  2, query table structure

desc table name;

  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

drop table Name;

  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;

drop table if exists table name;

Leave a Comment

Your email address will not be published.