SQL cell wise trigger

半腔热情 提交于 2019-12-11 07:18:34

问题


Can a specific cell wise trigger be created?

Or is

IF UPDATE(COLUMN) WHERE OTHER_COLUMN LIKE 'JT'

the equivalent present in SQL Server 2008?

EDIT after getting 2nd answer---

IF not UPDATE(CurrentNo) --// Wanted to do like this : where series ='JT'
    return

IF not EXISTS(SELECT 'True'
              FROM Inserted i
              JOIN Deleted d ON i.Series = d.Series
              WHERE i.Series = 'JT' AND d.Series = 'JT')
    return

Seems ok right! Please comment.


回答1:


No. There is no way of doing this declaratively. You would need to create a general Update trigger and put logic in it to return immediately IF NOT UPDATE (column)

If the column of interest was updated then you would query the inserted and deleted pseudo tables to allow you to process rows where your condition of interest was met.




回答2:


Tiggers are specified on tables, not on rows, columns or cells. Inside the body of the trigger you will have access to the INSERTED and DELETED tables. You can join them together to deterimine which columns were changed during an update. The UPDATE() function which is available in SQL Server 2008 (as well as previous versions) is a shorthand method for determining whether a column has changed.



来源:https://stackoverflow.com/questions/3904990/sql-cell-wise-trigger

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!