Operating the database table structure

Create a data table statement: create table;

create  table <表名> (

  Column Name Data Type 1 [Column-level constraint] Default],

  Column Name Data Type 2 [Column-level constraint] Default],

  .......

  [Table level constraint]

  )

View the data sheet:

show tables (from  db_name);

View the data sheet basic structure:

show columns from db_name;

desc <table name> / describe <table name>

View table details the structure of the statement, show create statement:

show create table db_name;

:( add columns to add columns in a list that already exists)

alter table <show> the Add <new list> <data type> [constraints] [first | after column names are present]

Modify the column name:

alter table <table name> Create <old column name> <new column name> <new data type>

Modify the data type

alter table <table name> Modify <column name> <data type>

Modified column arrangement position

alter table <table name> Modify <column> <data type> first | after <column name>;

Remove Columns

alter table <table name> drop <column name>;

Modify the table name

alter table <old table name> rename [to] <new table name>;

To delete a database table

drop table [if exits] 表1,表2......;

 

Guess you like

Origin www.cnblogs.com/wzc27229/p/11235644.html