我有一個名爲Page
的表,該表有一個名爲Priority
的列。我希望當我在頁表中插入一行時,優先級列取值爲插入行PageId
。 PageId
是我的表主鍵。如何在插入後爲sql server 2008製作觸發器?
我寫這觸發了它:
CREATE TRIGGER PagePriority
ON [Page]
AFTER INSERT
AS
Begin
update inserted
set [Priority]=(select PageId from [Page] where Page.PageId=inserted.PageId)
End
但我對set
行一些錯誤。
如何做到這一點?
無法更新「僞代碼表」'Inserted' - 你需要更新**自己的表,而不是**! –
@marc_s是的,你說的對,收下。謝謝。 –