日期:2014-05-17  浏览次数:20447 次

sql的触发器使用
我想在数据库插入数据的时候,如果那一列没有插入则显示为‘佚名' 
create TRIGGER Default_author 
  ON article 
  after INSERT
AS 
BEGIN
if((select author from article where author is null)>=0)
BEGIN
update article set author='佚名' where author is null
END
END
GO


------解决方案--------------------
楼上的应该就行啦
------解决方案--------------------
SQL code

--這種問題一般不用trigger,用默認值比較好
alter table article add constraint [DF_article_author] default ('佚名') for author
go