MySQL adds modifies and deletes table definitions such as columns and constraints
- 2020-06-15 10:24:11
- OfStack
ALTER TABLE: Add, modify, delete table columns, constraints, and other table definitions.
View the column: desc table name;
Modified table name: alter table t_book rename to bbb;
Add columns: alter table table name add column column name varchar(30);
Delete column: alter table table name drop column column name;
Modified column name: alter table bbb change nnnnn hh int;
Modify column name SQLServer: exec sp_rename' es38EN_ES39en. name','nn','column';
Modified column name Oracle: lter table bbb column nnnnn hh int;
Modify column attributes: alter table t_book modify name varchar(22);
sp_rename: A stored procedure built into SQLServer that USES and modifies table definitions.
MySQL view constraints, add constraints, delete constraints Add columns, modify columns, delete columns
View table field information: desc table name;
View all the information for the table: show create table table name;
Add primary key constraint: alter table constraint Primary key (form: PK_ table name) primary key table name (primary key field);
foreign key Slave table (foreign key field) references master table (primary key field)
Delete primary key constraint: alter table Table name drop primary key;
alter table Table name drop foreign key Foreign keys (case sensitive);
Modified table name: alter table t_book rename to bbb
Add columns: alter table table name add column column name varchar(30);
Delete column: alter table Table name drop column column name;
Modified column name: alter table bbb change nnnnn hh int
Modify column name SQLServer: exec sp_rename't_student ','nn','column';
Modified column name Oracle: alter table bbb column nnnnn to hh int
Modify column attributes: alter table t_book modify name varchar(22);
sp_rename: SQLServer's built-in stored procedure for modifying table definitions.
First, delete the primary key
alter table table_test drop primary key;
Then add the primary key
alter table table_test add primary key(id);
alter table test rename test1; -- Change the table name
alter table add column name varchar(10) not null; -- Add table columns
alter table wd_express drop column id; Delete table columns
alter table wd_express drop column tbid; Delete table columns
alter table wd_express change column ES218en_ES220en int -- Change the table column name
alter table wd_express add PRIMARY key (id);
alter table test address char(10) -- Modifies the table column type
||alter table test change address address char(40)
alter table change address address1 varchar(30)-- Modified table column name
View the column: desc table name;
Modified table name: alter table t_book rename to bbb;
Add columns: alter table table name add column column name varchar(30);
Delete column: alter table table name drop column column name;
Modified column name: alter table bbb change nnnnn hh int;
Modify column name SQLServer: exec sp_rename' es38EN_ES39en. name','nn','column';
Modified column name Oracle: lter table bbb column nnnnn hh int;
Modify column attributes: alter table t_book modify name varchar(22);
sp_rename: A stored procedure built into SQLServer that USES and modifies table definitions.
MySQL view constraints, add constraints, delete constraints Add columns, modify columns, delete columns
View table field information: desc table name;
View all the information for the table: show create table table name;
Add primary key constraint: alter table constraint Primary key (form: PK_ table name) primary key table name (primary key field);
foreign key Slave table (foreign key field) references master table (primary key field)
Delete primary key constraint: alter table Table name drop primary key;
alter table Table name drop foreign key Foreign keys (case sensitive);
Modified table name: alter table t_book rename to bbb
Add columns: alter table table name add column column name varchar(30);
Delete column: alter table Table name drop column column name;
Modified column name: alter table bbb change nnnnn hh int
Modify column name SQLServer: exec sp_rename't_student ','nn','column';
Modified column name Oracle: alter table bbb column nnnnn to hh int
Modify column attributes: alter table t_book modify name varchar(22);
sp_rename: SQLServer's built-in stored procedure for modifying table definitions.
First, delete the primary key
alter table table_test drop primary key;
Then add the primary key
alter table table_test add primary key(id);
alter table test rename test1; -- Change the table name
alter table add column name varchar(10) not null; -- Add table columns
alter table wd_express drop column id; Delete table columns
alter table wd_express drop column tbid; Delete table columns
alter table wd_express change column ES218en_ES220en int -- Change the table column name
alter table wd_express add PRIMARY key (id);
alter table test address char(10) -- Modifies the table column type
||alter table test change address address char(40)
alter table change address address1 varchar(30)-- Modified table column name