dbTalk Databases Forums  

Know the view name

microsoft.public.sqlserver.clients microsoft.public.sqlserver.clients


Discuss Know the view name in the microsoft.public.sqlserver.clients forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Rogers
 
Posts: n/a

Default Know the view name - 09-05-2007 , 11:30 PM






I want to create DDL trigger like if any view create in the database I want
to know the name of the view.

like


CREATE trigger trg_SelectViewRights on Database
FOR CREATE_VIEW
AS
BEGIN
SELECT OBJECT_NAME()
END


Can you correct me?

Thanks



Reply With Quote
  #2  
Old   
Hugo Kornelis
 
Posts: n/a

Default Re: Know the view name - 09-07-2007 , 05:30 PM






On Thu, 6 Sep 2007 00:30:03 -0400, Rogers wrote:

Quote:
I want to create DDL trigger like if any view create in the database I want
to know the name of the view.
Hi Rogers,

In a DDL trigger, data about the firing event is available through the
EVENTDATA() function. This returns an xml value, so you'll have to use
XQuery to extract individual values.

For finding the name of the view just created, you can use

CREATE TRIGGER trg_SelectViewRights ON DATABASE
FOR CREATE_VIEW
AS
BEGIN
SELECT EVENTDATA().value('(/EVENT_INSTANCE/ObjectName)[1]',
'nvarchar(128)');
END;
go


--
Hugo Kornelis, SQL Server MVP
My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.