设表 book有字段bookname ,bookid
游标
Declare book_cur cursor for //定义一个
select bookname from book WHERE bookid=100001 //使游标的值对应某一字段
OPEN book_cur //打开
FETCH NEXT from bookname INTO @cheng //循环取值
WHILE @@FETCH_STATUS = 0 //成功取值
BEGIN
print @cheng //处理
FETCH NEXT from tbl_cur INTO @cheng
END
CLOSE book_cur //关闭游标
触发器
CREATE TRIGGER trigger1 ON [dbo].[book]
FOR INSERT, UPDATE, DELETE
AS//定义触发器
declare @temp varchar(50)
begin
if update(book)
select @temp='你要改变字段的值'
update book set column1=@temp from inserted i where book.id=i.id //inserted代表新表
end
存储过程
CREATE PROCEDURE [OWNER].[pro1] (@book varchar(50),@bookid int output)AS//定义,output代表参数是输出值
begin
rollback.tran//事务处理,要对应
insert//处理语句//
commit.tran
end