一张表是合同信息表InfoHt
一张表是结算信息表InfoJs
当用户向InfoHt中插入数据时,数据库自动向InfoJs中插入数据
说明:InfoHt中的字段(HNo,HName,HtSum)InfoJs(HNO,JYfZk,JHtYe)
其中,InfoJs中的JYfZk(已付帐款)默认为0,JHtYe默认为与合同金额HtSum相等
两张表相关联的字段是HNo
下面是我写的触发器,可是提示错误21001:必须包含名称和文本域库名,我知道存储过程语法有问题,请高人指教这个触发器该如何写!谢谢!!!
create trigger ti_InfoHt on InfoHt
for insert
as
insert into InfoJs(HNO,JYfZk,JHtYe)
select HNo,0,HtSum
from inserted
group by HNo,HtSum
------解决方案--------------------
--try
create table InfoHt(HNo nvarchar(10),HName nvarchar(10),HtSum int)
create table InfoJs(HNO nvarchar(10),JYfZk int,JHtYe int)
create trigger tri_InfoHt on InfoHt
for insert
as
insert InfoJs(HNO,JYfZk,JHtYe)
select HNO,0,sum(HtSum)
from inserted
group by HNO
------解决方案--------------------
insert InfoJs(HNO,JYfZk,JHtYe)
select HNO,sum(0),sum(HtSum)
from inserted
group by HNO
------解决方案--------------------
是放在哪里执行的,估计是执行方式错误,语法没有错误,虽然逻辑有错误(上面已改过来)
------解决方案--------------------
create table InfoHt(HNo nvarchar(10),HName nvarchar(10),HtSum int)
create table InfoJs(HNO nvarchar(10),JYfZk int,JHtYe int)
create trigger tri_InfoHt on InfoHt
after insert
as
insert InfoJs(HNO,JYfZk,JHtYe)
select HNO,0,sum(HtSum)
from inserted
group by HNO