1、变量的声明和使用
declare @var as varchar(50)
set var='abcd'
2、IF循环
if isnull(@prjid,0)=0
begin
print '没有找到prjid!!!'
return
end
else
begin
--必须在这里写一些代码,否则会报错。
end
3、游标的使用
- declare curJD cursor for
- select id,fzbh from _tzk
- open curJD
- fetch next from curJD into @jdID,@paperno
- while @@FETCH_STATUS=0
- BEGIN
- --这里是一些处理代码
- fetch next from curJD into @jdID,@paperno
- END
- close curJD
- deallocate curJD
4、触发器的使用
关键在于inserted表和deleted表的使用
- ALTER TRIGGER RoleInsert ON [dbo].[roleName]
- AFTER INSERT
- AS
- declare @RoleID as bigint
- set @RoleID=(select roleid from inserted)
- insert into rolerule (roleid,menuid,pw)
- select @roleid,menuid,0 from menus where menus.menuid not in
- (select menuid from rolerule where roleid=@roleid)
- update rolerule set pw=1 where menuid in (select menuid from menus where always=1)
- and roleid in (select roleid from inserted)
然后有了这几个例子,其它的就是熟练的一个过程了