1、.1. 切换到Access的SQL视图或者打开SQL Server查询分析器进行定义操作2. 用SQL语言CREATE TABLE语句创建学生表student、课程表course和选课表SC;(字段类型及长度参照实验一) Create table student (sno char(8) ,sname varchar(8),ssex char(2),sdept varchar(20),sage int); Create table course(cno char(3) ,cname varchar(20),credit numeric(18,1),cpno char(3);Create tab
2、le sc(sno char(8) ,cno char(3) ,grade numeric(18,1); 3. 用SQL语言ALTER语句修改表结构;a) STUDENT表中SNO设为非空和唯一; Alter table student alter column sno char(8) not null; Alter table student add unique(sno);b) STUDENT表中增加一个字段SBIRTH,类型设置为日期时间类型,增加一个ADDRESS字段,类型为文本(字符); Alter table student add sbirth datetime; Alter t
3、able student add address text;c) 删除STUDENT表中ADDRESS字段; Alter table student drop column address; d) COURSE表中CNO字段设为非空和唯一; Alter table course alter column cno char(3) not null; Alter table course add unique(cno);4. 重新定义一个简单表,然后用SQL语言DROP语句删除该表结构; 创建表DX Create table DX(dx text) 删除表DX drop table DX5. 用S
4、QL语言CREATE INDEX语句定义表STUDENT的SNAME字段的降序索引; Create unique index STUsname on student(sname desc);6. 用SQL语言CREATE INDEX语句定义表SC的GRADE字段的升序索引; Create unique index SCgrade on sc (grade);7. 用SQL语言DROP语句删除索引;Drop index STUsname on student;Drop index SCgrade on sc;8. 输入部分数据,并试着修改其中的错误;在主键列为非空的前提下:设置student表中
5、sno为主键 Alter table student add constraint PKsno primary key(sno) 删除主键 alter table student drop constraint PKsno 设置course表中cno为主键 Alter table course add constraint PKcno primary key(cno)删除主键 alter table course drop constraint PKcno Alter table sc alter column sno char(8) not null;Alter table sc alter
6、 column cno char (3) not null;设置sc表中sno,cno联合为主键 alter table sc add constraint PKsnocno primary key(sno,cno), Constraint FKsno foreign key(sno) references student(sno), Constraint FKcno foreign key(cno) references course(cno);删除主键 alter table sc drop constraint PKsnocno; 删除外键 alter table sc drop con
7、straint FKsno,FKcno; 建表的时候直接定义主键和外键建立student表 Create table student (sno char(8) primary key, sname varchar(8), ssex char(2), sdept varchar(20), sage int); 建立course表 Create table course (cno char(3) primary key, cname varchar(20), credit numeric(18,1), cpno char(3);建立sc表 Create table sc (sno char(8) foreign key references student(sno), cno char(3) foreign key references course (cno) , grade numeric(18,1), Constraint SCsnocno primary key (sno,cno); .