日期:2014-05-18 浏览次数:20411 次
create table msg_mobile (mobile varchar(20), Msg varchar(100), state varchar(20), sendyorn varchar(20), sendtime datetime, id int not null identity(1,1) primary key, senduser varchar(20), CommPort varchar(10)) insert into msg_mobile (mobile,Msg,sendtime) values('13000010001','test',getdate()) select * from msg_mobile create TRIGGER [dbo].[trg_msg_mobile_insert] ON [dbo].[msg_mobile] FOR INSERT AS if (select count(*) from msg_mobile where exists (select * from inserted where inserted.mobile = msg_mobile.mobile and datediff(day,inserted.sendtime,msg_mobile.sendtime) = 0 and inserted.msg = msg_mobile.msg)) >1 begin raiserror 99999 '不能在同一天给同一用户发送同一内容的短信!' rollback tran return end insert into msg_mobile (mobile,Msg,sendtime) values('13000010001','test',getdate()) select * from msg_mobile /**** 消息 99999,级别 16,状态 1,过程 trg_msg_mobile_insert,第 12 行 不能在同一天给同一用户发送同一内容的短信! 消息 3609,级别 16,状态 1,第 1 行 事务在触发器中结束。批处理已中止。 ***/ insert into msg_mobile (mobile,Msg,sendtime) values('13000010001','test',getdate()) insert into msg_mobile (mobile,Msg,sendtime) values('13000010002','test',getdate()) insert into msg_mobile (mobile,Msg,sendtime) values('13000010002','test',getdate()) insert into msg_mobile (mobile,Msg,sendtime) values('13000010003','test',getdate()) insert into msg_mobile (mobile,Msg,sendtime) values('13000010003','test',getdate()) drop table msg_mobile
------解决方案--------------------
将发送成功的消息内容+手机号+发送日期保存下来,发送时按消息内容+手机号+发送日期查一下,有记录的不发送
------解决方案--------------------
是的,否则如何实现你的要求?