sqlserver數據庫 學生表,課程表,成績表,創建語句。

爲了方便練習相應語句,寫下此博文,用於快速建立一個簡單的數據庫。

 

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


 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章