具体的思路是这样的: 想在sqlservice2000里面建一个insert 触发器,在A表里插入一条数据的时候去建立另一个表,这个表是一天建一次,如果是本天插入5条数据,都是在一个表里面. 表名比如: XXXX_08_09 是月份加上日期!
use mas if exists (select name from sysobjects where name='tri_tbl_smsendtask_insert' AND type = 'TR') drop trigger tri_tbl_smsendtask_insert go create trigger tri_tbl_smsendtask_insert on tbl_smsendtask for insert as begin declare @tabName varchar(200),@sql varchar(1000),@dd varchar(10) if len(datename(dd,getdate()))=1 begin set @dd='0'+datename(dd,getdate()) end select @tabName='tbl_smresult_'+datename(mm,getdate())+@dd if(object_id(@tabName,'U'))is null begin set @sql='CREATE table '+ @tabName+'( [id] [int] IDENTITY (1, 1) NOT NULL , [Orgaddr] [varchar] (42) COLLATE Chinese_PRC_CI_AS NOT NULL , [Destaddr] [varchar] (72) COLLATE Chinese_PRC_CI_AS NOT NULL , [Sm_content] [varchar] (3200) COLLATE Chinese_PRC_CI_AS NULL , [Sendtime] [datetime] NULL , [Msg_status] [varchar] (20) COLLATE Chinese_PRC_CI_AS NULL , [Recv_status] [varchar] (20) COLLATE Chinese_PRC_CI_AS NULL ) ON [PRIMARY] ' end exec(@sql) end