嗨专家 我在sql server中有表。我想对它应用更新触发器。 我想更新具有触发器的同一个表。 任何人都可以帮助我做例子。
答案 0 :(得分:2)
您可以在SQL Server Management Studio模板资源管理器中找到此代码
--======================================
-- Create T-SQL Trigger Template
--======================================
USE <database_name, sysname, AdventureWorks>
GO
IF OBJECT_ID ('<schema_name, sysname, Sales>.<trigger_name, sysname, uStore>','TR') IS NOT NULL
DROP TRIGGER <schema_name, sysname, Sales>.<trigger_name, sysname, uStore>
GO
CREATE TRIGGER <schema_name, sysname, Sales>.<trigger_name, sysname, uStore>
ON <schema_name, sysname, Sales>.<table_name, sysname, Store>
AFTER <data_modification_statements, , UPDATE>
AS <T-SQL_statement, , UPDATE Sales.Store SET ModifiedDate = GETDATE() FROM inserted WHERE inserted.CustomerID = Sales.Store.CustomerID>
GO
一个简单的例子是
CREATE TRIGGER TriggerName ON TableName
AFTER UPDATE
AS
/* Some SQL Statements */
UPDATE TableName
SET ColumnName = 'SomeText'
GO