MySQL Create a table statement

Source: Internet
Author: User

1Show variables like 'character_set_client'; #查询字符集2 show databases; #列出所有的服务器上的数据库alter3 Create Database if  not existstest; #创建一个数据库4 Drop DatabaseFK; #删除数据库5Show tables fromtest; #显示一个数据库中的表6  Usetest;7 8 Create TableTb_dept (9Idint Primary Keyauto_increment, #部门编号 shaping primary key self-growthTenNamevarchar( -), #部门名称 OneDescriptionvarchar( -) #描述 A ); -  -Show tables fromtest; the  - desctb_dept; #查看表信息 -  -ShowCreate Tabletb_dept; +  -  Usetest; + #员工表 A Create TableTb_emp ( atIdint Primary Keyauto_increment, #auto_increment只是MySQL特有的 -Namevarchar( -), -Sexvarchar(2), -Ageint, -Addressvarchar( $), -Emailvarchar( -) in ); -  to Drop Tabletb_dept; + #修改列类型 - #注意: It is not possible to modify it under any circumstances, the #只有当字段只包含空值时才可以修改.  * Alter TableTb_emp Modify Sexvarchar(4); $ #增加列Panax Notoginseng Alter TableTb_empAddTelvarchar( A); - #删除列 the Alter TableTb_empDropTel; + Alter TableTb_empDrop columnTel; A #列改名 the Alter TableTb_emp Change Name emp_namevarchar( -); + #更改表名 - Alter Tabletb_emp rename emp; $RenameTableEmp totb_emp; $  - Insert  intoDept_emp (Name,sex,age,address,email)Values("',"',"',"',"'); -  the #约束 - #是在表上强制执行地数据校验规则, mainly used to ensure database integrityWuyi /* the Not null - Unique uniqueness Key Tb_depttb_dept Wu PRIMARY Key - foreign key foreign key About Check Checks $ */ -  - Create TableTb_emp ( -Idint Primary KeyAuto_increment, ANamevarchar( -), +Sexvarchar(2)default'male' Check(Sex='male'orSex='female'), #表级写法check does not work in MySQL theAgeint, -Addressvarchar( $), $Emailvarchar( -)Unique, thedept_idint,#Referencestb_dept (ID) #表级写法外键不起作用 the constraint Foreign KeyFk_emp (dept_id)Referencestb_dept (ID) the ); the  - #创建表之后在添加 in Alter TableTb_empAdd constraint Foreign KeyFk_emp (dept_id)ReferencesTb_dept (ID);

MySQL Create a table statement

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.