Mysql database learning-3. Table creation, deletion, and change
Create table mytbl (id int auto_increment not null, name char (10) not null, birth date not null, wight int, sex enum ('F ', 'M'); create table mytbl (id int auto_increment not null, name char (10) not null, birth date not null, wight int, sex enum ('F', 'M') engine = memory; create temporary table mytbl (id int auto_increment not null, name char (10) not null, birth date not null, wight int, sex enum ('F', 'M '));
Copy the data table structure (you can also create a temporary table as a copy to create temporary table tblnew like tblold) create table tblnew like tblold copy data insert into tblnew select * from tblold create table tblnew select * from tblold
Delete A data table
drop table tbl_namedrop table tbl_name ,tbl2_namedrop table if exists tbl_namedrop temporary table tbl_name
Modify a data table
Modify the Data Type of a data column alter table mytbl modify I mediumint unsignedalter table mytbl chang I mediumint unsigned modify the data type and character set alter table mytbl modify I mediumint character set ucs2 modify the data table storage engine alter table mytbl engine = engine_name
Rename the data table alter table tbl_name rename to new_tbl_namerename talbe tbl_name to new_tbl_name rename multiple data tables rename talbe tbl_name to new_tbl_name, t1 to t2, t3 to t4 move the data table to another database alter table db1.tbl _ name rename to db2.new _ tbl_namerename talbe db1.tbl _ name to db2.new _ tbl_name