事务、触发器、游标的定义
begin tran---声明事务
declare @err int
set @err =0
set @err=@err+@@ERROR
if(@@ERROR >0)
begin
rollback tran --回滚
end
commit tran--提交事务
CREATE trigger TRIG---声明触发器
on dbo.Food
after INSERT ,DELETE ,UPDATE
AS
BEGIN
SELECT * FROM DELETED
SELECT * FROM INSERTED
PRINT 'ok'
END
DECLARE CUR---声明游标
CURSOR FOR
SELECT FoodID FROM dbo.Food
OPEN CUR
DECLARE @I INT
FETCH NEXT FROM CUR INTO @I
WHILE @@FETCH_STATUS =0---当=0时,代表读到了数据
BEGIN
FETCH NEXT FROM CUR INTO @I
END
CLOSE CUR
DEALLOCATE CUR