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