---
title: "sql server 2008 触发器"
author: "freellf"
date: "2012-04-22T23:28:42Z"
tags: []
categories: ["数据库"]
slug: "sql-server-2008"
draft: false
lastmod: "2012-04-22T23:28:42Z"
id: 1494089
url: "https://freellf.iteye.com/blog/1494089"
---

library数据库中有一个book表  ，现在要在此表上创建一个 ”before行级触发器“ 
功能：检测插入book表的每一条记录，如果图书价格小于40元则更改为40元，大于40元得图书不作任何改变
book(book_id,book_name,price,press)

CREATE TRIGGER  ON . 
FOR INSERT
AS
begin
declare @price money,@BID int
select @BID=Book_ID from inserted
select @price=price from inserted
if @price<40
update Bussion set price=40 where Book_ID=@BID
end