创立触发器sql语句模板:
--======================================
--CreateT-SQLTriggerTemplate
--======================================
USE<database_name,sysname,AdventureWorks>
GO
IFOBJECT_ID(<schema_name,sysname,Sales>.<trigger_name,sysname,uStore>,TR)ISNOTNULL
DROPTRIGGER<schema_name,sysname,Sales>.<trigger_name,sysname,uStore>
GO
CREATETRIGGER<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,,UPDATESales.StoreSETModifiedDate=GETDATE()FROMinsertedWHEREinserted.CustomerID=Sales.Store.CustomerID>
GO
--================================================
--TemplategeneratedfromTemplateExplorerusing:
--CreateTrigger(NewMenu).SQL
--
--UsetheSpecifyValuesforTemplateParameters
--command(Ctrl-Shift-M)tofillintheparameter
--valuesbelow.
--
--SeeadditionalCreateTriggertemplatesformore
--examplesofdifferentTriggerstatements.
--
--Thisblockofcommentswillnotbeincludedin
--thedefinitionofthefunction.
--================================================
SETANSI_NULLSON
GO
SETQUOTED_IDENTIFIERON
GO
--=============================================
--Author:<Author,,Name>
--Createdate:<CreateDate,,>
--Description: <Description,,>
--=============================================
CREATETRIGGER<Schema_Name,sysname,Schema_Name>.<Trigger_Name,sysname,Trigger_Name>
ON<Schema_Name,sysname,Schema_Name>.<Table_Name,sysname,Table_Name>
AFTER<Data_Modification_Statements,,INSERT,DELETE,UPDATE>
AS
BEGIN
--SETNOCOUNTONaddedtopreventextraresultsetsfrom
--interferingwithSELECTstatements.
SETNOCOUNTON;
--Insertstatementsfortriggerhere
END
GO
修正触发器sql语句模板:
--======================================
--AlterT-SQLTriggerTemplate
--======================================
USE<database_name,sysname,AdventureWorks>
GO
ALTERTRIGGER<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,,UPDATESales.StoreSETModifiedDate=GETDATE()FROMinsertedWHEREinserted.CustomerID=Sales.Store.CustomerID>
GO
删除触发器sql语句模板:
--======================================
--DropTriggerTemplate
--======================================
USE<database_name,sysname,AdventureWorks>
GO