CREATE TABLE student
(
sno int PRIMARY KEY NOT NULL,
sname varchar(255),
year int,
dept varchar(255)
)
;
CREATE TABLE course
(
cno varchar(255) PRIMARY KEY NOT NULL,
cname varchar(255),
credit int,
dept varchar(255),
prname varchar(255)
)
;
CREATE TABLE enrol
(
sno int NOT NULL,
cno varchar(255) NOT NULL,
grade varchar(255),
midterm int,
final int,
CONSTRAINT enrol_pkey PRIMARY KEY (sno,cno)
)
;
ALTER TABLE "public"."enrol"
ADD CONSTRAINT enrol_sno_fkey
FOREIGN KEY (sno)
REFERENCES "public"."student"(sno)
;
ALTER TABLE "public"."enrol"
ADD CONSTRAINT enrol_cno_fkey
FOREIGN KEY (cno)
REFERENCES "public"."course"(cno)
;
INSERT INTO "public"."course" (cno,cname,credit,dept,prname) VALUES ('C123','프로그래밍',3,'컴퓨터','김성국');
INSERT INTO "public"."course" (cno,cname,credit,dept,prname) VALUES ('C312','자료구조',3,'컴퓨터','황수관');
INSERT INTO "public"."course" (cno,cname,credit,dept,prname) VALUES ('C324','파일구조',3,'컴퓨터','이규찬');
INSERT INTO "public"."course" (cno,cname,credit,dept,prname) VALUES ('C412','반도체',3,'전자','홍봉진');
INSERT INTO "public"."course" (cno,cname,credit,dept,prname) VALUES ('C413','데이터베이스',3,'컴퓨터','이일로');
INSERT INTO "public"."enrol" (sno,cno,grade,midterm,final) VALUES (100,'C413','A',90,95);
INSERT INTO "public"."enrol" (sno,cno,grade,midterm,final) VALUES (200,'C123','B',85,80);
INSERT INTO "public"."enrol" (sno,cno,grade,midterm,final) VALUES (300,'C312','A',90,95);
INSERT INTO "public"."enrol" (sno,cno,grade,midterm,final) VALUES (300,'C324','C',75,95);
INSERT INTO "public"."enrol" (sno,cno,grade,midterm,final) VALUES (300,'C413','A',95,90);
INSERT INTO "public"."enrol" (sno,cno,grade,midterm,final) VALUES (400,'C312','A',90,95);
INSERT INTO "public"."enrol" (sno,cno,grade,midterm,final) VALUES (400,'C324','A',95,90);
INSERT INTO "public"."enrol" (sno,cno,grade,midterm,final) VALUES (400,'C413','B',80,85);
INSERT INTO "public"."enrol" (sno,cno,grade,midterm,final) VALUES (500,'C312','B',85,80);
INSERT INTO "public"."student" (sno,sname,year,dept) VALUES (100,'나수영',4,'컴퓨터');
INSERT INTO "public"."student" (sno,sname,year,dept) VALUES (200,'이찬수',3,'전기');
INSERT INTO "public"."student" (sno,sname,year,dept) VALUES (300,'정기태',1,'컴퓨터');
INSERT INTO "public"."student" (sno,sname,year,dept) VALUES (400,'송병길',4,'컴퓨터');
INSERT INTO "public"."student" (sno,sname,year,dept) VALUES (500,'박종화',2,'산공');
카테고리 없음
참조 무결성 샘플 데이터
반응형
반응형