www.webdeveloper.com
Results 1 to 3 of 3

Thread: how to create a trigger?

  1. #1
    Join Date
    Apr 2013
    Posts
    1

    how to create a trigger?

    Hello,

    I want to create a trigger for the following table :



    This is my code :

    CREATE TABLE INVOICE (
    Invoice_id number CONSTRAINT Invoice_id_pk PRIMARY KEY,
    Invoice_date datetime NOT NULL DEFAULT CURDATE(),
    Invoice_location varchar2(150) NOT NULL,
    Invoice_order number CONSTRAINT Invoice_order_fk REFERENCES order_header(Order_id)
    );

    What would be the syntax for a trigger for the above table?
    I would really appreciate any help

    thnx!

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    18,936
    You don't say what DMBS you are using, so for now I'll assume MySQL and ask if you have looked at the manual pages yet, perhaps starting here?
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Sep 2011
    Posts
    58
    this is template for SQL server
    Code:
    --======================================
    --  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

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles