Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 trigger dilema

Author  Topic 

njahnavi
Starting Member

4 Posts

Posted - 2009-03-12 : 14:27:27
HI

I am new to sql server triggers...
when i try to create a trigger i am gettign this error

Msg 2103, Level 15, State 1, Procedure trig_addAuthor2, Line 17
Cannot create trigger 'testtable.trig_addAuthor2' because its schema is different from the schema of the target table or view.

i am just trying to create a simple trigger like

CREATE TRIGGER testtable.trig_addAuthor2

ON dbo.testtable

FOR INSERT

AS

-- Get the first and last name of new author

DECLARE @test VARCHAR(100)

SELECT @test = (SELECT testcolumn FROM Inserted)

-- Print the name of the new author

PRINT 'new data "' + @test + '" added.'

mfemenel
Professor Frink

1421 Posts

Posted - 2009-03-12 : 14:43:18
I'm going to assume that the table schema is dbo and not testtable. You should try replacing testtable.trig_addAuthor2 with dbo.trig_addAuthor2.

Mike
"oh, that monkey is going to pay"
Go to Top of Page

guptam
Posting Yak Master

161 Posts

Posted - 2009-03-13 : 00:57:07
When creating trigger the syntax is:

CREATE TRIGGER triggerName ON TableName

not

CREATE TRIGGER tablename.triggername ..

:)

Thanks.

--
Mohit K. Gupta
B.Sc. CS, Minor Japanese
MCITP: Database Administrator
MCTS: SQL Server 2005
http://sqllearnings.blogspot.com/
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-13 : 13:49:30
whats the default schema for user running this code?
Go to Top of Page

njahnavi
Starting Member

4 Posts

Posted - 2009-03-16 : 12:30:23
Thanks for the reply guys...
I have tried and it worked.
Go to Top of Page
   

- Advertisement -