MSSQL中int型相加的问题
create table aaa
(
id int;
single int;
more int;
total int;
)
让total的值=single+more,而且当我插入single和more的值后,total的值也计算出来自己加进去,该怎么做
答案:您的建表语句是:
create table aaa
(
id int,
single int,
more int,
total int
)
可以建立一个触发器
create trigger cal_total
on aaa
for insert,update
as
declare @_id as int
declare @_single as int
declare @_more as int
select @_id=i.id,@_single=i.single,@_more=i.more from inserted i
rollback tran
insert into aaa values(@_id,@_single,@_more,@_single+@_more)
测试用例:
insert into aaa values(1,2,3,'')
结果表中出现:
1 2 3 5
上一个:网站使用的asp+access,我想换成mssql数据库
下一个:请问MSSQL的问题