sqlserver数据库 学生表,课程表,成绩表,创建语句。

版权声明:本文为博主原创文章,转载需注明出处。 https://blog.csdn.net/AsynSpace/article/details/81017248

为了方便练习相应语句,写下此博文,用于快速建立一个简单的数据库。

create table Student
(
    Sno char(10)primary key,
    Sname char(10) unique,
    Ssex char(2) check (Ssex in ('男','女')), 
    Sage smallint check(Sage between 18 and 20),
    Sdept char(20),
);
create table Course(
	Cno char(4) primary key, 
	Cname char(20) not null,  
	Cpno char(4),
	Ccredit smallint,
	foreign key (Cpno) references Course(Cno), 
);
create table SC(
	Sno char(10),  
	Cno char(4),
	Grade smallint,
	primary key(Sno,Cno), 
	foreign key(Sno) references Student(Sno),
	foreign key(Cno) references Course(Cno)
);
insert into dbo.Student(Sno, Sname, Ssex, Sage, Sdept)
values('60001','zhangsan','女',18,'art'),
	  ('60002','lisi','女',18,'it'),
	  ('60003','wangwu','女',18,'art'),
	  ('60004','chenliu','女',18,'pe'),
	  ('60005','tisi','女',18,'pe');
	  
INSERT INTO [Course]([Cno],[Cname],[Cpno],[Ccredit])
     VALUES('1000','c#','1002',100),
			('1001','asp.net','1000',100),
			('1002','c',null,100),
			('1003','HTML',null,100),
			('1004','python',null,100),
			('1005','django','1004',100)
     
GO


INSERT INTO [SC]([Sno],[Cno],[Grade])
     VALUES('60001','1000','48'),
			('60002','1003','98'),
			('60001','1001','56'),
			('60001','1004','83'),
			('60001','1003','35'),
			('60002','1002','71'),
			('60003','1005','49'),
			('60005','1002','37')
GO

 

猜你喜欢

转载自blog.csdn.net/AsynSpace/article/details/81017248