Results 1 to 2 of 2

Thread: SP execution

  1. #1
    Join Date
    Apr 2003
    Posts
    176

    Unanswered: SP execution

    Can i write a trigger to execute a SP When one row is inerted into the table.If yes,can anyone let me know the syntax.
    Thanks.

  2. #2
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Sure, why not...
    Code:
    USE Northwind
    GO
    
    CREATE TABLE myTable99(Col1 int IDENTITY(1,1), Col2 char(1))
    CREATE TABLE myTable00(Col1 int IDENTITY(1,1), Col2 char(1))
    GO
    
    CREATE PROC mySproc99
    AS
    BEGIN
    INSERT INTO myTable00(Col2) 
         SELECT col2 
           FROM myTable99 
          WHERE Col1 = (SELECT MAX(Col1) FROM myTable99)
    END
    GO
    
    CREATE TRIGGER myTable99_TR1 ON myTable99
    FOR INSERT
    AS
    BEGIN
    EXEC mySproc99
    END
    GO
     
    INSERT INTO myTable99(Col2) SELECT 'a'
    GO
    
    SELECT * FROM myTable99
    SELECT * FROM myTable99
    GO
    
    DROP PROC  mySproc99
    DROP TABLE myTable99
    DROP TABLE myTable00
    GO
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

Posting Permissions

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