MSSQL trigger examples

My sample trigger SQL code in TSSQL for a SQL Server database for a Date.

CREATE TRIGGER img_file1_lastchanged ON [dbo].[IMG_FILE1]
FOR INSERT, UPDATE
AS
UPDATE img_file1 SET lastchanged = getdate()

More or less based on this:
http://www.sqlteam.com/article/creating-a-date-updated-field-in-tables

 

Another trigger example with CAST:

/* Create the 10 digit style member_number */
CREATE TRIGGER create_member_number ON [dbo].[member] 
FOR INSERT AS
UPDATE member SET member_number = '123' + RIGHT('0000000' + CAST(member_id AS varchar), 7) 

 

Tags: trigger, sqlserver, msssql, update, lastchanged, timestamp, automatic, sql
 

Related Scribbles:
  • Now() Equivalent in MSSQL
  • SQL Server


  • ID: 861
    Author:
    leonard
    Date Updated:
    2010-03-18 11:29:43
    Date Created:
    2007-08-15 12:42:38

    Edit

    Comments?
     >> Leonard Chan's Homepage  >> Scribble Web  >> MSSQL trigger examples
    leonard.lotus-land.ca is hosted by Perceptus Solutions Inc.