February 23, 2010 at 10:25 pm
This was removed by the editor as SPAM
February 24, 2010 at 1:26 am
The answer to this question should be NO.
The SQL as written will generate an error:
Msg 111, Level 15, State 1, Line 2
'CREATE TRIGGER' must be the first statement in a query batch.
If you take out the USE statement is works OK.
February 24, 2010 at 1:28 am
stewartc-708166 (2/23/2010)
point of note:Schema definitions are case sensitive.
therefore the schema of the table given as dbo, while the schema of the trigger is Dbo.
removing the trigger schema or making it the same case as the table/view definition will make it work.
otherwise the error will be:
Cannot create trigger 'Dbo.TvDiscontinuedProducts' because its schema is different from the schema of the target table or view.
What you say is not (completely) correct. What is true, is that the trigger and the table/view need to belong to the same schema.
When your database collation is case sensitive, then of course dbo and Dbo are two different schemas and then this error will occur.
February 24, 2010 at 1:36 am
jack.kennedy (2/24/2010)
The answer to this question should be NO.The SQL as written will generate an error:
Msg 111, Level 15, State 1, Line 2
'CREATE TRIGGER' must be the first statement in a query batch.
If you take out the USE statement is works OK.
Not sure what you do incorrect (forgot the GO), but even the code below works.
USE OPLIB
GO
CREATE TRIGGER DBO.TvDiscontinuedProducts ON dbo.vw_borrower
instead of insert AS Print 'inserts not authorized'
GO
USE OPLIB
GO
DROP TRIGGER DBO.TvDiscontinuedProducts
GO
Otherwise it would be quite impossible to make SQL batch file containing the creations of trigger otherwise.
Answer YES is the correct one.
February 24, 2010 at 1:41 am
Ah - what a dummy I am - Had the GO on the same line - that'll teach me to be so quick to criticize. I'll have to wait 24 hrs to redeem myself 😉
February 24, 2010 at 2:35 am
This was removed by the editor as SPAM
February 24, 2010 at 5:33 am
stewartc-708166 (2/24/2010)
Should have gone with my gut feel and not tested to confirm
I keep saying this to my lead developer. He doesn't really listen to me anymore, I'm not sure why. 😉
-----
a haiku...
NULL is not zero
NULL is not an empty string
NULL is the unknown
February 24, 2010 at 6:45 am
At first I was disturbed by the lack of a rollback, then realized it was an istead of trigger.
I'm going to use that in my robotic arsenal, thanks BB!
Craig Outcalt
February 24, 2010 at 9:09 am
Thanks Ron. Good question
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
February 24, 2010 at 11:16 am
I'd say the right answer is: it depends.
"INSTEAD OF triggers are not allowed on updatable views that use WITH CHECK OPTION."
So, we don't really have enough information to say whether a INSTEAD OF trigger can created on dbo.vDiscontinuedProducts.
February 24, 2010 at 12:38 pm
Nice tool to know of. BTW, although the QOD starts off saying "in SQL 2008...", the INSTEAD OF option is documented for SQL 2005 as well.
February 24, 2010 at 2:42 pm
Good question. Being fairly new to SQL Server, I would not have thought that views could have triggers. It seems counter-intuitive to me. I learned something new, AGAIN!! :w00t:
February 25, 2010 at 1:39 pm
The name of the trigger and the view differed only by a single letter, and I missed that. I thought they were named the same and was thus a trick question.
Bummer.
March 30, 2010 at 8:34 am
A PRINT statement in a trigger :sick:
Paul White
SQLPerformance.com
SQLkiwi blog
@SQL_Kiwi
Viewing 15 posts - 1 through 14 (of 14 total)
You must be logged in to reply to this topic. Login to reply