在数据库中建一个school库,库中有三个表,student、course、sc。
第一部分:
a) STUDENT表中SNO设为非空和唯一;
先查询student表中有没有SNO,然后用
alter table student
modify Sno char(8) NOT NULL UNIQUE;
b) STUDENT表中增加一个字段SBIRTH,类型设置为日期时间类型,放在sname列后面,增加一个ADDRESS字段,类型为文本(字符);
alter table student
add SBIRTH date;
alter table student modify SBIRTH int after sname;
c) 删除STUDENT表中ADDRESS字段;
alter table student drop column ADDRESS;
d) COURSE表中CNO字段设为非空和唯一;
alter table course modify Cno CHAR(3) NOT NULL UNIQUE;
e) 修改student表中sbirth列名为birthday;
alter table student change column SBIRTH birthday;
f) 修改student表中sage列的位置,修改在birthday后面;
alter table student modify Sage int after birthday;
g) 修改sname列名称为stuname;
alter table student chage column Sname Stuname VARCHAR(8);
第二部分: 用SQL语言DROP语句删除该表结构,注意主外键关系表删除顺序;
先删除外键,再删除主键
①先查看表有没有外键
②删除外键
③再次查看表中是否有外键
④依次删除表
注:
删除有外键关联的表,需要先删除外键表,再删除主键表