sql 语句基础
--查询学生中选修课程号 为1 的学生姓名select sname from studentwhere exists( select * from sc where student.sno = sc.sno and cno='1')--查询选修了全部课程的学生姓名select snamefrom studentwhere exists( select * from course where exists( select * from sc where sc.cno = course.cno and sc.sno = student.sno ))-- 左值链接, 外链接select student.sno,sname,ssex,sage,sdept,cno,gradefrom student left outer join sc on (student.sno = sc.sno)--建立唯一性索引create unique index stu on student(sno asc,cno desc)--having 代表着选择条件select sno from sc group by sno having sno <> '200215121'-- 修改数据表字段类型alter table student alter column comment char(255)alter table sc alter column grade smallint-- 添加数据表列alter table student add comment char(50)alter table student add S_enterence datetimealter table course add unique(cname)-- 模糊精确条件select *from coursewhere cname like 'DB\_design' escape '\'--查询课程名中含有DB_design的课程名--建立存储过程create procedure proc_insert_student @sno1 char(9),@sname char(20),@ssex char(2) = '男',@sage int,@sdept char(20)as begin insert into student(sno,sdept) values(@sno1,@sname,@ssex,@sage,@sdept)endcreate proc proc_avgrade_sc@sno char(9),@savg int output -- outas begin select @savg = avg(grade) from sc where sno = @sno end--执行存储过程 exec proc_insert_student '2002015126','张新阳','男',19,'CS' exec proc_insert_student @sno1 = '2002015128',@sname = '尼阳',@sage = 22,@sdept = 'IS'declare @avg int set @avg = 0 exec proc_avgrade_sc '200215121',@avg output --输出参数必须是output 类型--select @avg 平均成绩--删除存储过程drop prodc [procedure_name]总结
以上是内存溢出为你收集整理的SQLServer2005 高校教学语句全部内容,希望文章能够帮你解决SQLServer2005 高校教学语句所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)