473,405 Members | 2,445 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Getting error while creating a trigger with INSTEAD OF UPDATE

please help me,

I had created a table,

CREATE TABLE THETABLE
(
id_num int IDENTITY(1,1),
DT datetime,
NM varchar(30)
)


and then created a trigger on this table


CREATE TRIGGER myTRIGGER on THETABLE
INSTEAD OF UPDATE
AS
UPDATE THETABLE
SET
DT = GETDATE(),
NM = COALESCE(inserted.NM, USER)
FROM inserted
WHERE THETABLE.ID = inserted.ID
GO

But,I got the error while creating the trigger like this

Server: Msg 170, Level 15, State 1, Procedure myTRIGGER, Line 2
Line 2: Incorrect syntax near 'INSTEAD'.

please give me a solution
Aug 16 '07 #1
3 2399
azimmer
200 Expert 100+
please help me,

I had created a table,

CREATE TABLE THETABLE
(
id_num int IDENTITY(1,1),
DT datetime,
NM varchar(30)
)


and then created a trigger on this table


CREATE TRIGGER myTRIGGER on THETABLE
INSTEAD OF UPDATE
AS
UPDATE THETABLE
SET
DT = GETDATE(),
NM = COALESCE(inserted.NM, USER)
FROM inserted
WHERE THETABLE.ID = inserted.ID
GO

But,I got the error while creating the trigger like this

Server: Msg 170, Level 15, State 1, Procedure myTRIGGER, Line 2
Line 2: Incorrect syntax near 'INSTEAD'.

please give me a solution
in your table you use id_num, while in the trigger ID as column name use id_num in the trigger - it works fine (do not use keywords/reserved words as column names, it always leads to confusion)
Aug 16 '07 #2
in your table you use id_num, while in the trigger ID as column name use id_num in the trigger - it works fine (do not use keywords/reserved words as column names, it always leads to confusion)

Thanks for your help,

after changing id to id_num, this is showing the same error.

i had updated the trigger like this:


CREATE TRIGGER myTRIGGER on THETABLE
INSTEAD OF UPDATE
AS
UPDATE THETABLE
SET
DT = GETDATE(),
NM = COALESCE(inserted.NM, USER)
FROM inserted
WHERE THETABLE.id_num = inserted.id_num
GO


But it is showiing same error,

Server: Msg 170, Level 15, State 1, Procedure myTRIGGER, Line 2
Line 2: Incorrect syntax near 'INSTEAD'.


Please note that it is showing the error in Line 2:INSTEAD
Aug 17 '07 #3
azimmer
200 Expert 100+
Thanks for your help,

after changing id to id_num, this is showing the same error.

i had updated the trigger like this:


CREATE TRIGGER myTRIGGER on THETABLE
INSTEAD OF UPDATE
AS
UPDATE THETABLE
SET
DT = GETDATE(),
NM = COALESCE(inserted.NM, USER)
FROM inserted
WHERE THETABLE.id_num = inserted.id_num
GO


But it is showiing same error,

Server: Msg 170, Level 15, State 1, Procedure myTRIGGER, Line 2
Line 2: Incorrect syntax near 'INSTEAD'.


Please note that it is showing the error in Line 2:INSTEAD
I did note, in the previous version it did the same to me. I tried it, for me it shows no errors...

Expand|Select|Wrap|Line Numbers
  1. insert into thetable (DT,NM) values ('2007-01-01','A')
  2. update thetable set NM='B' where NM='A'
  3. select * from thetable
  4.  
results:
Expand|Select|Wrap|Line Numbers
  1. id_num      DT                               NM                             
  2. ----------- -------------------------------------- ------
  3. 1           2007-08-17 10:07:36.110    B
  4.  
So it does work. For me, at least.
Aug 17 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: M | last post by:
Hello, I have a very simple table, and want to create a trigger that updates the date column entry (with the current date), whenever a row gets modified. Is there a simple way of fixing this,...
2
by: moklet | last post by:
i've been trying to create an insert/update trigger on v_$session but with no success. following is my code: 1 create or replace trigger trg_module 2 instead of insert or update on t_$session...
1
by: efinney | last post by:
Hi, I'm a newbie to sql server and this may be a really dumb question for some you. I'm trying to find some examples of sql server triggers that will set columns (e.g. the created and modified...
3
by: takilroy | last post by:
Hi, Does anyone know of a simple way to do this? I want to create an insert trigger for a table and if the record already exists based on some criteria, I want to update the table with the...
5
by: Dave Sisk | last post by:
Hey folks: I'm trying to do this: CREATE TRIGGER datawhse.emp_ti AFTER INSERT ON emp REFERENCING NEW AS n FOR EACH ROW MODE DB2ROW BEGIN DECLARE v_rrn DECIMAL(15,0);
12
by: Bob Stearns | last post by:
I am trying to create a duplicate prevention trigger: CREATE TRIGGER is3.ard_u_unique BEFORE UPDATE OF act_recov_date ON is3.flushes REFERENCING NEW AS N FOR EACH ROW MODE DB2SQL WHEN...
3
by: teddysnips | last post by:
I need a trigger (well, I don't *need* one, but it would be optimal!) but I can't get it to work because it references ntext fields. Is there any alternative? I could write it in laborious code...
0
by: gshawn3 | last post by:
Hi, I am having a hard time creating a Trigger to update an Oracle database. I am using a SQL Server 2005 Express database on a Win XP Pro SP2 desktop, linked to an Oracle 10g database on a...
2
by: Reshmi Jacob | last post by:
Hello, Can any one help me in creating a trigger to update system date into a table while inserting a record into that table. I tried it like this, it is showing error !!! The following error...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.