24日SQL 練習前
create database lianxi
use lianxi
create table Student /*學生表*/
(Son varchar(20) not null primary key, /*學號(主)*/
Sname varchar(20) not null, /*姓名*/
Ssex varchar(20) not null, /*性別*/
Sbirthday datetime , /*出生年月*/
Class varchar(20), /*所在班級*/
)
create table Course /*課程表*/
(Cno varchar(20) not null primary key, /*課程號 (主)*/
Cname varchar(20) not null, /*課程名稱*/
Tno varchar(20) not null, /*教工編號(外)*/
)
create table Score /*成績表*/
(Sno varchar(20) not null, /*學號(外)*/
Con varchar(20) not null, /*課程號(外)*/
Decree Decimal(4,1) /*成績*/
)
create table Teacher /*教師表*/
(Tno varchar(20) not null primary key, /*教工編號(主)*/
Tname varchar(20) not null, /*教工姓名*/
Tsex varchar(20) not null, /*教工性別*/
Tbirthday datetime , /*教工出生日期*/
Prof varchar(20) , /*職稱*/
Depart varchar(20) not null, /*所在部門*/
)
alter table Score add constraint xuehao foreign key(Sno) references Student(Son)
alter table Score add constraint kechenghao foreign key(Con) references Course (Cno)
alter table Course add constraint jiaogong foreign key(Tno) references Teacher(Tno)
24日SQL 練習前