程序阅读题(10分)
下面程序段的功能是:在 数据库中判断是否存在名为my_proc的存储过程,若存在,则删除之,然后创建同名的存储过程,该存储过程的功能是向author_id、author_name、address和telephone字段插入数据。阅读并回答以下问题:
USE bookdb
GO
IF EXISTS(SELECT ① FROM Sysobjects
WHERE name=’my_proc’ and type=’ ② ’)
DROP PROC my_proc
GO
CREATE PROC my_proc
@a int, @b char(8),@c char(50)
③
INSERT INTO clients(client_id,client_name,address)
VALUES(@a,@b,@c)
GO
问题:(1)填写该程序段中空白处的内容:① ② ③
(2)任写一条调用该存储过程的语句: 。
1. name P as
2. EXEC my_proc 7,‘李好’,‘考试书店’或者 EXEC my_proc @a=7,@b=‘李好’,@c=‘考试书店’
1、 (4分)
update course (1分)
set 学分=4 (2分)
where课程号=2 (1分)
2、select * from student where 年龄>18 order by 学号 desc (5分)
1分 1分 1分 2分
3、(6分)
方法1:
select distinct student.学号,姓名,性别 (1分)
from student, course, sc (1分)
where (student.学号=sc.学号) and (course.课程号=sc.课程号)
and (course.学分=4) and (sc.成绩>80) (1+1+1+1分)
方法2:
select distinct student.学号,姓名,性别 (1分)
from student Inner Join (sc Inner Join course On course.课程号=sc.课程号)
On student.学号=sc.学号 (2分+2分)
where (course.学分=4) and (sc.成绩>80) (1分+1分)
4、(10分)
If exists(Select name From sysobjects
Where name=’my_trig’and type=’tr’) (整个If语句 1分)
Drop trigger my_trig (0.5分)
Go (0.5分)
Create trigger my_trig (1分)
On student (0.5分)
For Delete (1分)
As (0.5分)
Delete From sc (2分)
Where 学号 in (Select 学号 From Deleted) (1分+2分)
Go