首页 理论教育 更新记录数据

更新记录数据

时间:2023-02-28 理论教育 版权反馈
【摘要】:CREATE TABLE Department(dept char(20)primary key,office varchar(30)notnull,phone char(8)CHECK(phone LIKE′[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]′),dhead char(10),dorm char(20),CONSTRAINT FK_DEPT_DORM

图6.1 创建Dormitory表

(2)创建系部表(Department)

CREATE TABLE Department(dept char(20)primary key,office varchar(30)notnull,

phone char(8)CHECK(phone LIKE′[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]′),dhead char(10),dorm char(20),

CONSTRAINT FK_DEPT_DORM FOREIGN KEY(dorm)REFERENCESDormitory(dorm))

(3)创建学生表(Student)

CREATE TABLE student(sno char(7)primary key,sn char(10)not null,

sex char(2)CHECK(sex in(′男′,′女′)) DEFAULT′男′,

birthday smalldatetime,

dept char(20)CONSTRAINT FK_stu_dept FOREIGN KEY(dept)REFERENCESDe-partment(dept),

class char(10))

(4)创建教师表(Teacher)

CREATE TABLE Teacher(

tno char(5)primary key,

tn char(10)not null,

sex char(2)CHECK(sex=′男′OR sex=′女′)DEFAULT′男′,

birthday smalldatetime,

dept char(20)CONSTRAINT FK_teacher_dept FOREIGN KEY(dept)REFERENCES Department(dept)

(5)创建课程表(Course)

CREATE TABLE Course(cno char(5)primary key,

cn char(20)not null unique,

credit numeric(3,1)CHECK(credit>=0 AND credit<=20),

ct int CHECK(ct BETWEEN 8 AND 320)

(6)创建选修表(SC)

CREATE TABLE SC(

sno char(7)CONSTRAINT FK_Stu REFERENCESStudent(SNO),cno char(5) REFERENCESCourse(CNO),score tinyint CHECK(score>=0 AND score<=100),CONSTRAINT PK_SC PRIMARY KEY(SNO,CNO))

(7)创建授课表(TC)

CREATE TABLE TC(

tno char(5)CONSTRAINT FK_Tea REFERENCESTeacher(TNO),cno char(5)CONSTRAINT FK_Cou REFERENCESCourse(CNO),dct int CHECK(dct>=0 AND dct<=320),

CONSTRAINT PK_TC PRIMARY KEY(Tno,CnO))

至此,所有数据表全部创建完毕。从对象资源管理器窗口即可看到这7张表,如图6.2所示。

免责声明:以上内容源自网络,版权归原作者所有,如有侵犯您的原创版权请告知,我们将尽快删除相关内容。

我要反馈