CSDN同名博文传送门:https://blog.csdn.net/ChaoYang_183/article/details/104871387

·用命令创建关系对象


CREATE TABLE Student(

Sno CHAR(9) PRIMARY KEY,

Sname CHAR (20) UNIQUE,

Ssex CHAR(2),

Sage SMALLINT,

Sdept CHAR(20)

);



CREATE TABLE Course(

Cno CHAR(4) PRIMARY KEY,

cname CHAR(40),

cpno CHAR(4),

ccredit SMALLINT,

FOREIGN KEY (cpno) REFERENCES course (cno)

);



CREATE TABLE SC(

Sno CHAR(9),

Cno CHAR(4),

Grade SMALLINT,

PRIMARY KEY (Sno,Cno),

FOREIGN KEY (Sno) REFERENCES student(sno),

FOREIGN KEY (cno) REFERENCES Course(cno)

);

·将数据添加到关系对象内


INSERT INTO student VALUES('201215121','李勇','男',20,'CS');

INSERT INTO student VALUES('201215122','刘晨','女',19,'CS');

INSERT INTO student VALUES('201215123','王敏','女',18,'MA');

INSERT INTO student VALUES('201215125','张立','男',19,'IS');



INSERT INTO course VALUES('6','数据处理',null,2);

INSERT INTO course VALUES('2','数学',null,2);

INSERT INTO course VALUES('4','操作系统','6',3);

INSERT INTO course VALUES('7','PASCAL语言','6',4);

INSERT INTO course VALUES('5','数据结构','7',4);

INSERT INTO course VALUES('1','数据库','5',4);

INSERT INTO course VALUES('3','信息系统','1',4);



INSERT INTO SC VALUES('201215121','1',92);

INSERT INTO SC VALUES('201215121','2',85);

INSERT INTO SC VALUES('201215121','3',88);

INSERT INTO SC VALUES('201215122','2',90);

INSERT INTO SC VALUES('201215122','3',80);

·在student关系内添加一列entrydaty属性(日期类型)


ALTER TABLE student ADD entrydate DATE;

·实验截图

student表

course表

sc表