如何创建一存储过程SP_Student_insert

来源:百度知道 编辑:UC知道 时间:2024/06/06 11:56:37
实现对表Student插入记录。该存储过程应具备获取外部各字段参数传入值,以及判断是否存在重复SNO值,如存在则退出,不存在则插入等功能。
该表的代码是
create table Student
(sno char(8) primary key,
sname char(8),
ssex char(2),
sage int,
sdept char(20),
)

create procedure SP_Student_insert
(@SNO char(8),
@sname char(8),
@ssex char(2),
@sage int,
@sdept char(20))

as

if exists(select *
from Student
where SNO = @SNO)
begin
--如果存在 ,退出
return
end

--如果不存在,添加
INSERT INTO STUDENT(sno, sname, ssex, sage, sdept)
VALUES(sno, sname, ssex, sage, sdept)
……
……

GO