English 中文(简体)
B. 需要帮助的一般更新触发器
原标题:Need help with generic update trigger

I m使用2008年服务器,并想知道是否有办法撰写一个通用的更新触发器,以检查所更新的表格是否有一个称为“最后更新”的外地,如果是的话,则以“获得”的功能更新这个领域。

我能否写出一个像我的布局中所有表格一样通用的触发点?

感谢你们的时间!

最佳回答

页: 1 最后,每个最新资料中都注明了最新数据。

尝试:

SELECT 
     CREATE TRIGGER [tr_u_ +TABLE_SCHEMA+ _ +TABLE_NAME+ ] ON [ +TABLE_SCHEMA+ ].[ +TABLE_NAME+ ] 
        + AFTER UPDATE AS  
        + UPDATE [ +TABLE_SCHEMA+ ].[ +TABLE_NAME+ ]  
        +     SET Last_Updated=GETDATE()  
        +     FROM [ +TABLE_SCHEMA+ ].[ +TABLE_NAME+ ]  A  
        +     INNER JOIN INSERTED  i ON a.pk=i.pk  
    FROM INFORMATION_SCHEMA.COLUMNS 
    WHERE COLUMN_NAME= LastChgDate  -- Last_Updated 

这一查询将产生一个<代码>Create Trigger的每个表格的指令,该表格有Last_Updated栏。 页: 1 然后由所有指挥员领导,然后由你负责。 当你增加新的表格时,你需要增加触发因素。

问题回答

您可以查取图谋信息。 表格在您的触发点中看到,将触发点分派到所有表格中,但这只是做事的明显方式。 各位最好不要写出某些法规的生成者,以便每个表格都这样做,而不是有一个普遍触发因素。





相关问题
How to write this T-SQL WHERE condition?

I ve got two tables: TableA Col1 Col2 TableB Col3 Col4 I want to join them together: SELECT * from TableA join TableB ON (...) Now, in place of ... I need to write an expression ...

Customer and Order Sql Statement

TSQL query to select all records from Customer that has an Order and also select all records from customer that does not have an Order. The table Customer contains a primary key of CustomerID. The ...

Recommended way of querying multiple Versioned tables

Have a win 2003 box with MSSQL 2005 running on it. There is a database which is populated every morning with new/modified SalesOrder made the previous day. The database has several tables: SalesOrder, ...

update duplicate record

I have a table with the following fields Id Name IsPublic i need to write a sql query that updates IsPublic to false where name has a duplicate. Only one of the duplicates should have IsPublic = ...

Define variable to use with IN operator (T-SQL)

I have a Transact-SQL query that uses the IN operator. Something like this: select * from myTable where myColumn in (1,2,3,4) Is there a way to define a variable to hold the entire list "(1,2,3,4)"? ...

Selecting records during recursive stored procedure

I ve got a content management system that contains a hierarchical structure of categories, with sub-categories subject to different ordering options at each level. Currently, that s retrieved by a (...

热门标签