CREATE DATABASE 成绩管理系统
GO
USE 成绩管理系统
GO
CREATE TABLE DEPT--专业
(
D_NO CHAR(2)PRIMARY KEY NOT NULL CHECK(D_NO LIKE '[0-9][0-9]'),
D_NAME NCHAR(50)NOT NULL UNIQUE
)
CREATE TABLE CLASS--班级
(
CL_NO CHAR(4)PRIMARY KEY NOT NULL CHECK(CL_NO LIKE '[0-9][0-9][0-9][0-9]'),
CL_NAME NCHAR(50)NOT NULL UNIQUE,
CL_NUM INT DEFAULT(0),
D_NO CHAR(2),
CONSTRAINT FK_D_NO FOREIGN KEY(D_NO)REFERENCES DEPT(D_NO),
CONSTRAINT CK_CL_NO CHECK(CL_NO LIKE D_NO+'[0-9][0-9]')
)
CREATE TABLE DORM--宿舍
(
DO_NO CHAR(3)PRIMARY KEY NOT NULL CHECK(DO_NO LIKE '[0-9][0-9][0-9]'),
DO_NUM INT DEFAULT(0),
DO_LEVEL CHAR(7)CHECK(DO_LEVEL IN('STUDENT','TEACHER')),
DO_SEX CHAR(5)CHECK(DO_SEX IN('MEN','WOMEN')),
CONSTRAINT CK_DO_NUM_DO_LEVEL CHECK(DO_NUM<=1 AND DO_LEVEL='TEACHER' OR DO_LEVEL='STUDENT')
)
CREATE TABLE CLASSROOM--教室
(
CR_NO CHAR(3)PRIMARY KEY CHECK(CR_NO LIKE '[0-9][0-9][0-9]')
)
CREATE TABLE TEACHER--教师
(
T_NO CHAR(3)PRIMARY KEY CHECK(T_NO LIKE '[0-9][0-9][0-9]'),
T_NAME NCHAR(30)NOT NULL,
T_SEX CHAR(5)CHECK(T_SEX IN('MEN','WOMEN')),
T_AGE INT CHECK(T_AGE BETWEEN 20 AND 70),
DO_NO CHAR(3),
D_NO CHAR(2),
CONSTRAINT FK_D_NO1 FOREIGN KEY(D_NO)REFERENCES DEPT(D_NO),
CONSTRAINT FK_DO_NO FOREIGN KEY(DO_NO)REFERENCES DORM(DO_NO)
)
CREATE TABLE COURSE--课程--有错
(
C_NO CHAR(3)PRIMARY KEY CHECK(C_NO LIKE '[0-9][0-9][0-9]'),
C_NAME NCHAR(50)NOT NULL,
D_NO CHAR(2),
CR_NO CHAR(3)UNIQUE,
T_NO CHAR(3),
CREDIT INT CHECK(CREDIT BETWEEN 1 AND 9),
CONSTRAINT FK_D_NO2 FOREIGN KEY(D_NO)REFERENCES DEPT(D_NO),
详细解决方案
求组,新手SQL求改进,有有关问题的地方都标了,求高手赐教
热度:69 发布时间:2016-04-24 20:50:14.0
相关解决方案