473,657 Members | 2,409 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting error while creating a trigger with INSTEAD OF UPDATE

17 New Member
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(insert ed.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 2416
azimmer
200 Recognized Expert New Member
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(insert ed.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
ramesh1210
17 New Member
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(insert ed.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 Recognized Expert New Member
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(insert ed.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
7463
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, or would I have to create 3 extra triggers, a package, etc., as described in most posts about mutating table errors? Could you please explain to me WHY this error happens here (I have not been able to find a clear explanation of what causes them)?
2
8544
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 3 begin 4 delete from t_modes; 5* end; SQL> /
1
17334
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 date columns) if the row is being inserted and set a column (e.g. just the modified date column) if the row is being updated. I know how to do this in oracle plsql. I would define it as a before insert or update trigger and reference old and new...
3
7276
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 values that are passed in via the insert trigger without having to use all the 'set' statements for each field (so if we add fields in the future I won't have to update the trigger). In other words, I want the trigger code to look something like...
5
11546
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
4750
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 (N.act_recov_date IS NOT NULL) BEGIN ATOMIC select count(*) into v_n from is3.flushes
3
3721
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 in the application, but I'd rather not! DDL for table and trigger below. TIA
0
3010
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 remote Windows 2003 server. Both machines are on the same domain and very close physically (<1ms ping). I have set up the Oracle linked server in SQLEXPRESS, added the login/pw information, and I can execute select and update queries
2
12205
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 has occurred: ORA-04091: table ACG.CENTREMST is mutating, trigger/function may not see it ORA-06512: at "ACG.CENTREMST_INSERT", line 5 ORA-04088: error during execution of trigger 'ACG.CENTREMST_INSERT'
0
8395
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8310
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8826
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8732
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8605
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4155
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4306
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1955
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1615
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.