学生选课系统数据库设计

CREATE TABLE Student
	(S# varchar2(8) PRIMARY key,
	Sname varchar2(10),
	Ssex CHAR(2) CONSTRAINT ctssex CHECK(Ssex='男' OR Ssex='女'),
	Sage number(2) CHECK(Sage>=1 AND Sage<150)
	D# CHAR(2) REFERENCES Dept(D#) ON DELETE cascade,
	Sclass varchar2(16));
CREATE TABLE Dept
	(D# VARCHAR2(2) PRIMARY key,
	Dname varchar2(10),
	Dean varchar2(10));
CREATE TABLE Course
	(C# varchar2(3) PRIMARY key,
	Cname varchar2(12),
	Chours numbers(2),
	Credit number(3,1) CONSTRAINT ctscredit CHECK(Credit >=0.0 AND Credit <=5.0),
	T# varchar2(3) REFERENCES Teacher(T#) ON DELETE cascade);
CREATE TABLE Teacher
	(T# varchar2(3) PRIMARY key,
	Tname varchar2(10),
	D# varchar2(2),
	Salary number(6,2)
	FOREIGN KEY(D#) REFERENCES Dept(D#) ON DELETE cascade)
CREATE TABLE SC
	(S# varchar2(8) PRIMARY key,
	C# VARCHAR2(3),
	Score number(4,1) CONSTRAINT ctsscore CHECK(Score <=0.0 AND Score <=100.0),
	FOREIGN KEY(S#) REFERENCES Student(S#) ON DELETE cascade,
	FOREIGN KEY(C#) REFERENCES Course(C#) ON DELETE cascade)

学生选课系统ER图设计

你可能感兴趣的:(sql)