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
3 2399
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)
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
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... -
insert into thetable (DT,NM) values ('2007-01-01','A')
-
update thetable set NM='B' where NM='A'
-
select * from thetable
-
results: -
id_num DT NM
-
----------- -------------------------------------- ------
-
1 2007-08-17 10:07:36.110 B
-
So it does work. For me, at least.
Sign in to post your reply or Sign up for a free account.
Similar topics
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,...
|
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...
|
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...
|
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...
|
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);
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
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,...
|
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,...
|
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...
|
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...
|
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,...
|
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...
| |