- 论坛徽章:
- 0
|
Create table product
(
pId char(6) primary key,
pName varchar(300) not null,
pPrice smallmoney,
pNum float
)
go
Create table sale
(
sNo int identity(1001,1) primary key,
sId char(6),
sPrice smallmoney,
sDate datetime
)
go
用触发器实现:
update product set pNum=pNum-x where pid=a
当这个发生的时候,sale表中插入数据,插入的行数 为 x(假设x为整数)
当x为float时候(比如x=5.5),插入的行数为6行。
如何实现。。。
Create trigger trgCheck
On product
For Update
As
Begin
Declare add_data cursor
For
Select pId,pPrice from Inserted
Open add_data
Declare @Id char(6),@Price smallmoney
Fetch Next From add_data into @Id,@Price
while(@@Fetch_status=0)
begin
Insert into Sale(sId,sPrice,sDate) values(@Id,@Price*1.2,getDate())
Fetch Next From add_data into @Id,@Price
end
Close add_data
deallocate add_data
End----------------------------这个是错误的,可能缺少pnum的判断吧。。。如何写?
求救下
[ 本帖最后由 JJooO 于 2008-7-3 11:20 编辑 ] |
|