--创建学生表,包括:学号,学生姓名,出生年月,性别
create table [wmj_Student]
(
[StudentId] bigint not null,
[StudentName] nvarchar(100) null,
[Birthday] datetime null,
[Gender] bit not null
constraint [pk_student_id] primary key clustered ([StudentId] asc)
)
--添加学生数据
insert into [wmj_Student]
([StudentId],[StudentName],[Birthday],[Gender])
values
(0001,'猴子',1989-1-1,1),
(0002,'猴子',1989-12-21,0),
(0003,'马云',1991-12-21,1),
(0004,'王思聪',1990-12-21,1)
--创建课程表,包括:课程号,课程名称,教师号
create table [wmj_Course]
(
[CourseId] bigint primary key not null, --主键
[CourseName] nvarchar(100) null,
fk_teacher_id bigint foreign key references wmj_Teacher --外键
)
--添加课程表数据
insert into [wmj_Course]
([CourseId],[CourseName],fk_teacher_id)
values
(1001,'语文',0002),
(1002,'数学',0001),
(1003,'英语',0003)
--创建成绩表(模拟学生表和课程表的关系),包括:学生学号,课程号,成绩
create table [wmj_Score]
(
[StudentId] bigint constraint fk_student_id foreign key references wmj_Student,
[CourseId] bigint foreign key references wmj_Course,
[Score] int null
constraint pk_student_id_score_id primary key(StudentId,CourseId) --将学号和课程号作为主键
)
--导入excel数据
--创建教师表,包括:教师号,教师姓名
create table [wmj_Teacher]
(
[TeacherId] bigint not null,
[TeacherName] nvarchar(100) null
constraint [pk_teacher_id] primary key clustered ([TeacherId] asc)
)
--添加老师数据
insert into [wmj_Teacher]
([TeacherId],[TeacherName])
values
(0001,'孟扎扎'),
(0002,'马化腾'),
(0003,null)
版权归原作者 会跳舞的程序媛 所有, 如有侵权,请联系我们删除。