Mysql database learning-3. Table creation, deletion, and change

Source: Internet
Author: User

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

 


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.