sql server数据库语句
-- 3-5 创建表Studnet
create table Student
(Sno char(9) primary key,
Sname char(20) UNIQUE,
Ssex CHAR(2),
Sage smallint,
Sdept char(20)
);
-- 3-6 创建表Course
create table course
(Cno char(4) primary key ,
Cname char(40) not null,
Cpno char(4),
Ccredit smallint,
foreign key (cpno) references course(cno)
);
-- 3-7 创建表SC
create table SC
(
Sno char(9),
Cno char(4),
Grade smallint,
primary key(Sno,Cno),
foreign key (Sno) references Student(Sno),
foreign key (Cno) references Course(Cno)
);
-- 3-8向Studnet表中添加入学时间列
alter table Student Add S_entrance Date;
-- 3-9 修改age 的数据类型
alter table Student alter column Sage int;
-- 3-10 使得Cname为唯一
alter table Course add unique(Cname);
-- 3-12 查询Student表中的所有数据
select * from Student;
-- 向Student表中添加数据
insert into Student values('12','kjdfh','1',12,'yd','2016-12-10');
-- 3-12 删除相应表信息
drop table Student CASCADE;
-- 3-13
--按学号升序建立唯一索引
create unique index Stusno ON Student(Sno);
--按课程号升序建立唯一
create unique index Coucno ON Course(Cno);
-- 按学号升序、课程号降序家建立唯一索引
create unique index sCno ON SC(Sno ASC,Cno DESC);
-- 3-14 将SC表的SCno 索引名修改为SCSno
alter index SCno RENAME TO SCSno;
-- 3-15 删除Student 表的Stusname索引
drop index Stusname;
-- 3-16 查询全体学生的学号与姓名
select Sno,Sname from Student;
-- 3-17 查询全体学生的姓名、学号、所在系
select Sname,Sno,Sdept
from Student;
-- 3-18 查询全体学生的详细记录
Select * from Student;
-- 3-19 查询全体学生的姓名、及其出生年份
select Sname,2014-Sage from Student;
-- 3-20 查询全体学生的姓名、出生年份和所在的院系,要求用小写字母表示系名
select Sname,'Year of irth:',2014-Sage,LOWER(Sdept) from Student;
-- 3-21 查询选修了课程的学生学号
select Sno from SC;
-- 3-22 查询计算机科学系的全体学生的名单
select Sname from Student where Sdept='CS';
-- 3-23 查询所有考试年龄在20 岁以下的学生姓名及年龄
select Sname,Sage from Student where Sage<20;
-- 3-24 查询考试成绩不及格的学生学号

浙公网安备 33010602011771号