Example of a statement that reproduces MySQL create table

Source: Internet
Author: User
Tags mysql create mysql create table

Show variables like 'character_set_client'; #查询字符集show databases; #列出所有的服务器上的数据库alterCreate Database if  not existstest; #创建一个数据库Drop DatabaseFK; #删除数据库show tables fromtest; #显示一个数据库中的表 Usetest;Create Tabletb_dept (Idint Primary Keyauto_increment, #部门编号 shaping primary key self-growing Namevarchar( -), #部门名称 descriptionvarchar( -) #描述); Show Tables fromtest;desctb_dept; #查看表信息showCreate Tabletb_dept; Usetest; #员工表Create Tabletb_emp (IDint Primary Keyauto_increment, #auto_increment只是MySQL特有的Namevarchar( -), Sexvarchar(2), ageint, Addressvarchar( $), emailvarchar( -));Drop Tabletb_dept, #修改列类型 # Note: Not all cases can be modified, #只有当字段只包含空值时才可以修改. Alter TableTb_emp Modify Sexvarchar(4); #增加列Alter TableTb_empAddTelvarchar( A); #删除列Alter TableTb_empDropTel;Alter TableTb_empDrop columnTel; #列改名Alter TableTb_emp Change Name emp_namevarchar( -); #更改表名Alter Tabletb_emp Rename Emp;renameTableEmp totb_emp;Insert  intoDept_emp (Name,sex,age,address,email)Values("',"',"',"',"'); #约束 # is a data validation rule on a table that is enforced to ensure database integrity/*Not null unique unique key Tb_depttb_deptprimary key foreign key foreign key check check*/Create Tabletb_emp (IDint Primary KeyAuto_increment,namevarchar( -), Sexvarchar(2)default'male' Check(Sex='male'orSex='female'), #表级写法check does not work in MySQLint, Addressvarchar( $), emailvarchar( -)Unique, dept_idint,#Referencestb_dept (ID) #表级写法外键不起作用constraint Foreign KeyFk_emp (dept_id)Referencestb_dept (ID)); #创建表之后在添加Alter TableTb_empAdd constraint Foreign KeyFk_emp (dept_id)ReferencesTb_dept (ID);

Example of a statement that reproduces MySQL create table

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.