这样写
create trigger xxx
as
delete from your_table where username in (select username from inserted where username is null or username ='')可能效率不会很高。不过,你既然不允许它空,那么为什么不设该字段非空呢?
create trigger xxx
as
delete from your_table where username in (select username from inserted where username is null or username ='')可能效率不会很高。不过,你既然不允许它空,那么为什么不设该字段非空呢?
但这种机制很没有'科学道理'
你不妨这样解决:
1.把该字段设为非空.
2.在插入这条记录之前判断username是否为空
as
if (select count(*) from table
where
username = (select username from inserted)) > 1
rollback transaction
goIt will be ok.
as
if (select count(*) from table
where
username = (select username from inserted)) > 1
rollback transaction
goIt will be ok.
insert into table
select * form table1这种做法,我想我无能为力。
:(
begin tran
if ...
rollback tran
else
commit tran
但限制同楼上所说一样,你的注意增加语句的写法!
asif exists (select * from inserted as a inner join table as b on a.username=b.username)
rollback transactionreturn