Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 24th, 2004, 11:07 AM
Authorized User
 
Join Date: Jul 2004
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default Trigger Creation Syntax Error

I'm trying to create a trigger to insert a row from tblSet to tblSetHistory when a column is updated:

USE smallcha
IF EXISTS (SELECT name FROM sysobjects
  WHERE name = 'tblSet_update' AND type = 'TR')
    DROP TRIGGER tblSet_update
GO
  CREATE TRIGGER tblSet_update ON tblSet
    FOR UPDATE AS
      IF UPDATE(WFState)= 1
        INSERT INTO tblSetHistory
          SELECT * FROM INSERTED tblSet
GO

which returns "Server: Msg 170, Level 15, State 1, Procedure tblSet_update, Line 3. Line 3: Incorrect syntax near '='." What am I doing wrong?
 
Old July 24th, 2004, 12:59 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

IF UPDATE(WFState) returns TRUE, but you are checking for 1 and use BEGIN...END to group your statements, in case you have separated those lines of INSERT statement into 2 lines.

Hope that helps.
Cheers!

_________________________
- Vijay G
Strive for Perfection
 
Old July 25th, 2004, 11:47 AM
Authorized User
 
Join Date: Jul 2004
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you, happygv. I removed "= 1" from what Server states is my line 3.

Now I get ""Server: Msg 8101, Level 16, State 1, Procedure tblSet_update, Line 4. An explicit value for the identity column in table 'tblSetHistory' can only be specified when a column list is used and IDENTITY_INSERT is ON." Does this mean I can't insert the entire row from tblSet as is?
 
Old July 25th, 2004, 12:28 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi there,

Your tblSetHistory table has got an IDENTITY column in it, into which you are trying to insert data using a select statement followed in your Trigger. So to get that work you must use it this way.
Code:
Set IDENTITY_INSERT tblSetHistory ON
    Insert INTO tblSetHistory ... ...
Set IDENTITY_INSERT tblSetHistory OFF
If you want the SQL server to handle adding value to the INDENTITY column in that table, you got to select only the columns other thatn IDENTITY column for adding in your Insert statement.

Hope that helps.
Cheers!

_________________________
- Vijay G
Strive for Perfection





Similar Threads
Thread Thread Starter Forum Replies Last Post
Ch 4: Parse error: syntax error, unexpected T_SL hanizar77 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 0 June 23rd, 2008 09:17 PM
error in word VBA to automate creation of mailing dgr7 Word VBA 1 April 4th, 2007 08:34 AM
Set operator error durn materialized view creation indupriyav Oracle 0 December 3rd, 2005 08:05 AM
Trigger Error kuku SQL Server 2000 7 August 25th, 2005 10:29 PM
Error about trigger Blueman137 Oracle 2 March 10th, 2004 08:53 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.