首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

sql 2000一条记录同时插入多张表?解决思路

2012-01-12 
sql 2000一条记录同时插入多张表?我写了一个触发器,在满足条件下,把新增记录同时插入多张表应该怎么操作?i

sql 2000一条记录同时插入多张表?
我写了一个触发器,在满足条件下,把新增记录同时插入多张表应该怎么操作?
if   条件
    insert   into   sms_send(mobile,content)  
    select   distinct   sms_receive.mobile   mobile,   '123 '   content  
    FROM     sms_receive
  else   if   条件
    insert   into   sms_send(mobile,content)  
      select   distinct   sms_receive.mobile   mobile,   '123 '   content  
      from   sms_receive
else
  insert   into   sms_send(mobile,content),SaveMobile(mobile)  
    select   distinct   sms_receive.mobile   mobile,       '123 '   content  
    from   sms_receive
  insert   into   SaveMobile(mobile)  
    select   distinct   sms_receive.content   mobile   from   sms_receive
应该怎么写在最后一个insert不会做判断,不满足条件的也会插入SaveMobile,
请教应该怎么写?

[解决办法]
if 条件
begin
insert into sms_send(mobile,content)
select distinct sms_receive.mobile mobile, '123 ' content
FROM sms_receive
end
else if 条件
begin
insert into sms_send(mobile,content)
select distinct sms_receive.mobile mobile, '123 ' content
from sms_receive
end
else
begin
insert into sms_send(mobile,content),SaveMobile(mobile)
select distinct sms_receive.mobile mobile, '123 ' content
from sms_receive
end
insert into SaveMobile(mobile)
select distinct sms_receive.content mobile from sms_receive

热点排行