1.建立一个“学生”表 Student
create table student_muanfeng(
sno char(4) primary key(主键),
Sname char(20) unique(为约束),
Ssex char(2) null check(sex in(‘M‘,‘F‘)),
Sage smallint null check(age>18 and age<25),
Sdept char(20)
);
2.建立一个“课程”表Course
Create table Course(
Cno char(4) primary key,
Cname char(40),
Credit smallint null check(credit>0 and credit<10)
);
)
3,建立学生学生选课表 SC
Create table SC
sno char(4) not null ,cno char(4) not null primary key(sno,cno),
grade smallint null check(grade>0 and grade <100))
alter table SC add constraint fk_sno foreign key(sno) references Student(sno);
alter table SC add constraint fk_cno foreign key(cno) references Course(cno);
2.Create table SC(
Sno char(4),
Cno Char(4),
Primary key (Sno,Cno),
Frimary key(Sno) reference student(Sno),
Frimary key(Cno) reference Course(Cno),
);
插入数据:
insert into 表名称(条件)value(相对应的值)