标签:alter mat tab sele 9.png http where val ble
/*学习事物基本语法*/
/*增加课室名的唯一索引*/
ALTER table class add constraint uni_ClassName unique(name)
/*创建存储过程,其中增加教师,并增加课室*/
CREATE proc pro_AddClass
@className varchar(50),
@teacherName varchar(50)
as
begin
declare @teacherid int
select @teacherid=id from teacher a where a.name=@teachername
begin tran
IF(@teacherid=0 or @teacherid is null)
begin
insert into teacher(name) VALUES(@teachername)
select @teacherid=IDENT_CURRENT(‘teacher‘)
end
insert into class(teacherid,name) VALUES(@teacherid,@classname)
IF @@error<>0
begin
rollback tran
end
else
commit tran
end
/*执行存储过程,查看结果*/
exec pro_AddClass ‘Soft‘,‘Teacher Li‘
exec pro_AddClass ‘Math‘,‘Teacher Ann‘
主要还是记录自己学习的过程,这些基础的知识相信园内已经有很多分享,参考了各位的资料,再作为自学的记录而已,如有差错,请指正
标签:alter mat tab sele 9.png http where val ble
原文地址:http://www.cnblogs.com/jia168/p/7698609.html