问题描述
使用PowerDesign15.1产生了触发器,但是提示错误:/*==============================================================*//*DBMSname:MicrosoftSQLServer2008*//*Createdon:2014/9/109:15:51*//*==============================================================*/ifexists(select1fromsysobjectswhereid=object_id('"CLRTrigger_article"')andtype='TR')droptrigger"CLRTrigger_article"goifexists(select1fromsysobjectswhereid=object_id('ti_article')andtype='TR')droptriggerti_articlegoifexists(select1fromsysobjectswhereid=object_id('tu_article')andtype='TR')droptriggertu_articlegoifexists(select1fromsysobjectswhereid=object_id('"CLRTrigger_xk_column"')andtype='TR')droptrigger"CLRTrigger_xk_column"goifexists(select1fromsysobjectswhereid=object_id('td_xk_column')andtype='TR')droptriggertd_xk_columngoifexists(select1fromsysobjectswhereid=object_id('Article')andtype='U')droptableArticlegoifexists(select1fromsysobjectswhereid=object_id('Xk_Column')andtype='U')droptableXk_Columngoifexists(select1fromsysobjectswhereid=object_id('Xk_Config')andtype='U')droptableXk_Configgo/*==============================================================*//*Table:Article*//*==============================================================*/createtableArticle(idintnotnull,ColumnIdintnull,Titlevarchar(200)null,Authorvarchar(10)null,PostDatedatetimenull,IsPicintnull,PicUrlvarchar(200)null,Bodytextnull,constraintPK_ARTICLEprimarykey(id))go/*==============================================================*//*Table:Xk_Column*//*==============================================================*/createtableXk_Column(idintidentity,Titlevarchar(50)null,Codevarchar(2000)null,constraintPK_XK_COLUMNprimarykey(id))go/*==============================================================*//*Table:Xk_Config*//*==============================================================*/createtableXk_Config(idintnotnull,Titlevarchar(50)null,CopyRightvarchar(400)null,Modeintnull,constraintPK_XK_CONFIGprimarykey(id))godeclare@CurrentUsersysnameselect@CurrentUser=user_name()executesp_addextendedproperty'MS_Description','0=aspx,1=html,2=urlrewrite','user',@CurrentUser,'table','Xk_Config','column','Mode'gocreatetrigger"CLRTrigger_article"onArticleinsertasexternalname%Assembly.GeneratedName%.gocreatetriggerti_articleonArticleforinsertasbegindeclare@numrowsint,@numnullint,@errnoint,@errmsgvarchar(255)select@numrows=@@rowcountif@numrows=0return/*Parent"Xk_Column"mustexistwheninsertingachildin"Article"*/ifupdate(ColumnId)beginselect@numnull=(selectcount(*)frominsertedwhereColumnIdisnull)if@numnull!=@numrowsif(selectcount(*)fromXk_Columnt1,insertedt2wheret1.id=t2.ColumnId)!=@numrows-@numnullbeginselect@errno=50002,@errmsg='Parentdoesnotexistin"Xk_Column".Cannotcreatechildin"Article".'gotoerrorendendreturn/*Errorshandling*/error:raiserror@errno@errmsgrollbacktransactionendgocreatetriggertu_articleonArticleforupdateasbegindeclare@numrowsint,@numnullint,@errnoint,@errmsgvarchar(255)select@numrows=@@rowcountif@numrows=0return/*Parent"Xk_Column"mustexistwhenupdatingachildin"Article"*/ifupdate(ColumnId)beginselect@numnull=(selectcount(*)frominsertedwhereColumnIdisnull)if@numnull!=@numrowsif(selectcount(*)fromXk_Columnt1,insertedt2wheret1.id=t2.ColumnId)!=@numrows-@numnullbeginselect@errno=50003,@errmsg='Xk_Column"doesnotexist.Cannotmodifychildin"Article".'gotoerrorendendreturn/*Errorshandling*/error:raiserror@errno@errmsgrollbacktransactionendgocreatetrigger"CLRTrigger_xk_column"onXk_Columninsertasexternalname%Assembly.GeneratedName%.gocreatetriggertd_xk_columnonXk_Columnfordeleteasbegindeclare@numrowsint,@errnoint,@errmsgvarchar(255)select@numrows=@@rowcountif@numrows=0return/*Deleteallchildrenin"Article"*/deleteArticlefromArticlet2,deletedt1wheret2.ColumnId=t1.idreturn/*Errorshandling*/error:raiserror@errno@errmsgrollbacktransactionendgo
解决方案
解决方案二:
createtrigger"CLRTrigger_article"onArticleinsertasexternalname%Assembly.GeneratedName%.gocreatetrigger"CLRTrigger_xk_column"onXk_Columninsertasexternalname%Assembly.GeneratedName%.go
改成createtrigger"CLRTrigger_article"onArticleforinsertasexternalname你定义的程序集名称.Triggers.UF_DML_Trigger;gocreatetrigger"CLRTrigger_xk_column"onXk_Columnforinsertasexternalname你定义的程序集名称.Triggers.UF_DML_Trigger;go
解决方案三:
老大能解释下为什么我是使用PD自动生成的,但是语句里面且没有添加for?还有就是@errno,那里都是现实添加(
解决方案四:
解决方案五:
解决了吗?我也碰到了这个问题。