Showing posts with label views. Show all posts
Showing posts with label views. Show all posts

Monday, March 26, 2012

Finding all views with a specific name, in all databases

Hi,

We are migrating to SQL Server 2005 from 2000 and we have a view created in many of our databases. That view must be changed after the migration because it uses system tables and does not return the correct information in SQL Server 2005.

To do that, I want to create an SSIS-package that loops through all the databases on a particular server. If that view exists in the database, I want to run a script that change the view.

What I try to do:

    Set up a For Each Loop container with Foreach SMO Enumerator

    Set the connection to my server

    Set the Enumerate property to "SMOEnumObj[@.Name='Databases']/SMOEnumType[@.Name='Names']"

    On the Variable Mapping page, place Index 0 in Variable User::dbName

    In the For Each Loop, place a script task to msgbox the value of User::dbName

This all works good. The problem comes when I try to nest the For Each Loop

    Inside the "For Each Database Loop", place a new For Each Loop container with Foreach SMO Enumerator

    I connect the Msgbox Script Task with the new For each loop

    Use the same connection

    Set the EnumURN property in the Expression Builder to "Database[@.Name='" + @.[User::dbName] +"']/SMOEnumObj[@.Name='Views']/SMOEnumType[@.Name='Names']"

    On the Variable Mapping page, place index 0 in Variable User::tabName

    In the For Each Loop, place a script task to msgbox the value of User::tabName

When I try to run the package now, it does not at all.

In my Progress tab I see that Validation has started and completed for each task, but I see now errors. Nothing has run.

Test 1: I change the DelayValidation for the Inner Loop to True

Now the package runs, but I never get to the script task in the inner loop.

Question 1: What's the problem?

Question 2: Is there another way to do this?

Regards

Magnus

Have you tried using a second connection? It seems like the above should work for you, but maybe there's an issue with the SMO Enumerator that requires a different connection for the inner loop.|||

Hi Sean, and thanks for your response.

I tried to use a second connection, but I still get the same result.

/Magnus

|||Forget the SMO enumerator in your Foreach loop.

Do an Execute SQL Task and use something like:

SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.VIEWS
WHERE TABLE_NAME LIKE 'VIEWNAME%'

Then set the resultset to full result set and create an object type var to hold the results. Then loop thru the results using the ForEach ADO.

See this example. I found it very helpful.

http://www.cubido.at/Blog/tabid/176/EntryID/59/Default.aspx|||

Hi Tom, I tried your suggestion and it worked alright. Thanks!

Because I only expect a single row, I used a Single Row instead of Full ResultSet and used a SQL like

SELECT ISNULL(Max(TABLE_NAME), '') AS TableName FROM [databasename].INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = 'viewName'

I set the SQLStatement with an expression since I needed to change the databasename for each iteration. I placed the field TableName in a variable. Before I move on to the next step, where I want to alter the view, I use a Constraint and Expression constraint and make sure that the variable is not empty.

Then I create an Execute SQL task to alter the view. I use the same connection as in the above task and use an expression to create the SQLStatement to something like:

USE [databasename]
GO

ALTER VIEW [dbo].[viewName]
AS
SELECT *
FROM theTable

/Magnus

|||

I had the same problem except I wasn't using SMO Enumeration for the outter loop. You can't just use set the EnumURN property in the Expression Builder to...
"Database[@.Name='" + @.[User::dbName] +"']/SMOEnumObj[@.Name='Views']/SMOEnumType[@.Name='Names']"

Your missing two parts. You have to set the Expression to...
"RuntimeServer[@.Name='<the name of your SMO Connection in the Connection Manager>']/Server[@.Name='<the server name>']/Database[@.Name='" + @.[User::dbName] +"']/SMOEnumObj[@.Name='Views']/SMOEnumType[@.Name='Names']"

Hope this at least helps someone down the road. It took me 4 hours to figure it out! Either I'm retarded or it's not explained well.

sql

Finding all views with a specific name, in all databases

Hi,

We are migrating to SQL Server 2005 from 2000 and we have a view created in many of our databases. That view must be changed after the migration because it uses system tables and does not return the correct information in SQL Server 2005.

To do that, I want to create an SSIS-package that loops through all the databases on a particular server. If that view exists in the database, I want to run a script that change the view.

What I try to do:

    Set up a For Each Loop container with Foreach SMO Enumerator

    Set the connection to my server

    Set the Enumerate property to "SMOEnumObj[@.Name='Databases']/SMOEnumType[@.Name='Names']"

    On the Variable Mapping page, place Index 0 in Variable User::dbName

    In the For Each Loop, place a script task to msgbox the value of User::dbName

This all works good. The problem comes when I try to nest the For Each Loop

    Inside the "For Each Database Loop", place a new For Each Loop container with Foreach SMO Enumerator

    I connect the Msgbox Script Task with the new For each loop

    Use the same connection

    Set the EnumURN property in the Expression Builder to "Database[@.Name='" + @.[User::dbName] +"']/SMOEnumObj[@.Name='Views']/SMOEnumType[@.Name='Names']"

    On the Variable Mapping page, place index 0 in Variable User::tabName

    In the For Each Loop, place a script task to msgbox the value of User::tabName

When I try to run the package now, it does not at all.

In my Progress tab I see that Validation has started and completed for each task, but I see now errors. Nothing has run.

Test 1: I change the DelayValidation for the Inner Loop to True

Now the package runs, but I never get to the script task in the inner loop.

Question 1: What's the problem?

Question 2: Is there another way to do this?

Regards

Magnus

Have you tried using a second connection? It seems like the above should work for you, but maybe there's an issue with the SMO Enumerator that requires a different connection for the inner loop.|||

Hi Sean, and thanks for your response.

I tried to use a second connection, but I still get the same result.

/Magnus

|||Forget the SMO enumerator in your Foreach loop.

Do an Execute SQL Task and use something like:

SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.VIEWS
WHERE TABLE_NAME LIKE 'VIEWNAME%'

Then set the resultset to full result set and create an object type var to hold the results. Then loop thru the results using the ForEach ADO.

See this example. I found it very helpful.

http://www.cubido.at/Blog/tabid/176/EntryID/59/Default.aspx|||

Hi Tom, I tried your suggestion and it worked alright. Thanks!

Because I only expect a single row, I used a Single Row instead of Full ResultSet and used a SQL like

SELECT ISNULL(Max(TABLE_NAME), '') AS TableName FROM [databasename].INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = 'viewName'

I set the SQLStatement with an expression since I needed to change the databasename for each iteration. I placed the field TableName in a variable. Before I move on to the next step, where I want to alter the view, I use a Constraint and Expression constraint and make sure that the variable is not empty.

Then I create an Execute SQL task to alter the view. I use the same connection as in the above task and use an expression to create the SQLStatement to something like:

USE [databasename]
GO

ALTER VIEW [dbo].[viewName]
AS
SELECT *
FROM theTable

/Magnus

|||

I had the same problem except I wasn't using SMO Enumeration for the outter loop. You can't just use set the EnumURN property in the Expression Builder to...
"Database[@.Name='" + @.[User::dbName] +"']/SMOEnumObj[@.Name='Views']/SMOEnumType[@.Name='Names']"

Your missing two parts. You have to set the Expression to...
"RuntimeServer[@.Name='<the name of your SMO Connection in the Connection Manager>']/Server[@.Name='<the server name>']/Database[@.Name='" + @.[User::dbName] +"']/SMOEnumObj[@.Name='Views']/SMOEnumType[@.Name='Names']"

Hope this at least helps someone down the road. It took me 4 hours to figure it out! Either I'm retarded or it's not explained well.

Friday, March 23, 2012

find which sprocs/views reference a table

Is there a quick way to find what sprocs/views reference a table within ?
Does sp_depends work accurately ?
sp_depends can not be relied on if you cannot guarentee the database has been
built in the correct order. As far as we know we're the only provider of an
application that can do this.
regards,
Mark Baekdal
www.dbghost.com
+44 (0)208 241 1762
Living and breathing database change management for SQL Server
"Hassan" wrote:

> Is there a quick way to find what sprocs/views reference a table within ?
> Does sp_depends work accurately ?
>
>
|||Hi Hassan
sp_depends has been notorious for years. If you want a quick, simple answer,
you can simply select the procs from syscomments where the name of the table
is in the text of the sprocs / views. Otherwise, I'd recommend you check out
SQL Scribe which is a nice 3rd party tool that does the trick nicely.
http://www.ag-software.com
Regards,
Greg Linwood
SQL Server MVP
"Hassan" <fatima_ja@.hotmail.com> wrote in message
news:u4w6JtIyEHA.3416@.TK2MSFTNGP09.phx.gbl...
> Is there a quick way to find what sprocs/views reference a table within ?
> Does sp_depends work accurately ?
>
|||As mentioned, the dependency records in a SQL Server database can be
problematic.
The SQL Server Tools WT3 application addresses the problems. It can list
dependencies as reflected in the dependency records. It can list
dependencies as found with a text search. It can rebuild the dependency
records to their original/correct state. It can generate detailed database
documentation, including dependencies. All of this for $19, which is about
1/20 (5%) of a previously mentioned product.
Please visit http://www.sqlservertools.us for more information.
"Hassan" wrote:

> Is there a quick way to find what sprocs/views reference a table within ?
> Does sp_depends work accurately ?
>
>

find which sprocs/views reference a table

Is there a quick way to find what sprocs/views reference a table within ?
Does sp_depends work accurately ?sp_depends can not be relied on if you cannot guarentee the database has been
built in the correct order. As far as we know we're the only provider of an
application that can do this.
regards,
Mark Baekdal
www.dbghost.com
+44 (0)208 241 1762
Living and breathing database change management for SQL Server
"Hassan" wrote:
> Is there a quick way to find what sprocs/views reference a table within ?
> Does sp_depends work accurately ?
>
>|||Hi Hassan
sp_depends has been notorious for years. If you want a quick, simple answer,
you can simply select the procs from syscomments where the name of the table
is in the text of the sprocs / views. Otherwise, I'd recommend you check out
SQL Scribe which is a nice 3rd party tool that does the trick nicely.
http://www.ag-software.com
Regards,
Greg Linwood
SQL Server MVP
"Hassan" <fatima_ja@.hotmail.com> wrote in message
news:u4w6JtIyEHA.3416@.TK2MSFTNGP09.phx.gbl...
> Is there a quick way to find what sprocs/views reference a table within ?
> Does sp_depends work accurately ?
>|||As mentioned, the dependency records in a SQL Server database can be
problematic.
The SQL Server Tools WT3 application addresses the problems. It can list
dependencies as reflected in the dependency records. It can list
dependencies as found with a text search. It can rebuild the dependency
records to their original/correct state. It can generate detailed database
documentation, including dependencies. All of this for $19, which is about
1/20 (5%) of a previously mentioned product.
Please visit http://www.sqlservertools.us for more information.
"Hassan" wrote:
> Is there a quick way to find what sprocs/views reference a table within ?
> Does sp_depends work accurately ?
>
>

find which sprocs/views reference a table

Is there a quick way to find what sprocs/views reference a table within ?
Does sp_depends work accurately ?sp_depends can not be relied on if you cannot guarentee the database has bee
n
built in the correct order. As far as we know we're the only provider of an
application that can do this.
regards,
Mark Baekdal
www.dbghost.com
+44 (0)208 241 1762
Living and breathing database change management for SQL Server
"Hassan" wrote:

> Is there a quick way to find what sprocs/views reference a table within ?
> Does sp_depends work accurately ?
>
>|||Hi Hassan
sp_depends has been notorious for years. If you want a quick, simple answer,
you can simply select the procs from syscomments where the name of the table
is in the text of the sprocs / views. Otherwise, I'd recommend you check out
SQL Scribe which is a nice 3rd party tool that does the trick nicely.
http://www.ag-software.com
Regards,
Greg Linwood
SQL Server MVP
"Hassan" <fatima_ja@.hotmail.com> wrote in message
news:u4w6JtIyEHA.3416@.TK2MSFTNGP09.phx.gbl...
> Is there a quick way to find what sprocs/views reference a table within ?
> Does sp_depends work accurately ?
>|||As mentioned, the dependency records in a SQL Server database can be
problematic.
The SQL Server Tools WT3 application addresses the problems. It can list
dependencies as reflected in the dependency records. It can list
dependencies as found with a text search. It can rebuild the dependency
records to their original/correct state. It can generate detailed database
documentation, including dependencies. All of this for $19, which is about
1/20 (5%) of a previously mentioned product.
Please visit http://www.sqlservertools.us for more information.
"Hassan" wrote:

> Is there a quick way to find what sprocs/views reference a table within ?
> Does sp_depends work accurately ?
>
>

Find Views with NOEXPAND

Hi,
Anyone out there know how to tell whether a view uses the WITH (NOEXPAND)
hint (other than searching the syscomments table for 'NOEXPAND')?
Thank you,
Daniel Jameson
SQL Server DBA
Children's Oncology Group
www.childrensoncologygroup.org
Another method is to script the view create statements and then search the
scripts for the NOEXPAND keyword.
Hope this helps.
Dan Guzman
SQL Server MVP
"Daniel Jameson" <djameson@.childrensoncologygroup.org> wrote in message
news:ejRg3RwQGHA.5924@.TK2MSFTNGP09.phx.gbl...
> Hi,
> Anyone out there know how to tell whether a view uses the WITH (NOEXPAND)
> hint (other than searching the syscomments table for 'NOEXPAND')?
> --
> Thank you,
> Daniel Jameson
> SQL Server DBA
> Children's Oncology Group
> www.childrensoncologygroup.org
>

Find Views with NOEXPAND

Hi,
Anyone out there know how to tell whether a view uses the WITH (NOEXPAND)
hint (other than searching the syscomments table for 'NOEXPAND')?
Thank you,
Daniel Jameson
SQL Server DBA
Children's Oncology Group
www.childrensoncologygroup.orgAnother method is to script the view create statements and then search the
scripts for the NOEXPAND keyword.
Hope this helps.
Dan Guzman
SQL Server MVP
"Daniel Jameson" <djameson@.childrensoncologygroup.org> wrote in message
news:ejRg3RwQGHA.5924@.TK2MSFTNGP09.phx.gbl...
> Hi,
> Anyone out there know how to tell whether a view uses the WITH (NOEXPAND)
> hint (other than searching the syscomments table for 'NOEXPAND')?
> --
> Thank you,
> Daniel Jameson
> SQL Server DBA
> Children's Oncology Group
> www.childrensoncologygroup.org
>sql

Find Views with NOEXPAND

Hi,
Anyone out there know how to tell whether a view uses the WITH (NOEXPAND)
hint (other than searching the syscomments table for 'NOEXPAND')?
--
Thank you,
Daniel Jameson
SQL Server DBA
Children's Oncology Group
www.childrensoncologygroup.orgAnother method is to script the view create statements and then search the
scripts for the NOEXPAND keyword.
--
Hope this helps.
Dan Guzman
SQL Server MVP
"Daniel Jameson" <djameson@.childrensoncologygroup.org> wrote in message
news:ejRg3RwQGHA.5924@.TK2MSFTNGP09.phx.gbl...
> Hi,
> Anyone out there know how to tell whether a view uses the WITH (NOEXPAND)
> hint (other than searching the syscomments table for 'NOEXPAND')?
> --
> Thank you,
> Daniel Jameson
> SQL Server DBA
> Children's Oncology Group
> www.childrensoncologygroup.org
>

Wednesday, March 7, 2012

find invalid views etc.

Hi,
Newbie as I am I cannot find the method to track down invalid objects in a MS SQLServer database.
Looking through documentation and looking at internet does not provide much help.
Please help
WilcoThe only method you find is the one you create using the Mark 1 mod 0 eyeball!!

For instance ... you create and sucessfully compile a sproc. Then you alter the schema of the table and drop a column. The proc knows nothing about the altered table until you try to execute it, at which time SQL Server will throw the error.

find indexes

I'm a new user of SQL Server.
What's the script to find out all indexes for tables and
views?
Thanks.Hi,
sp_helpindex <table name or view name>
You can also use the below statement to get all the information of the
object (including index).
sp_help <table or view name>
Thanks
Hari
MCDBA
"Julia" <KQD02@.YAHOO.COM> wrote in message
news:143d001c444cd$ab9aa640$a601280a@.phx.gbl...
> I'm a new user of SQL Server.
> What's the script to find out all indexes for tables and
> views?
> Thanks.|||Thanks, is it possible to get all indexes for all tables
and views in one script?
>--Original Message--
>Hi,
>sp_helpindex <table name or view name>
>You can also use the below statement to get all the
information of the
>object (including index).
>sp_help <table or view name>
>Thanks
>Hari
>MCDBA
>
>"Julia" <KQD02@.YAHOO.COM> wrote in message
>news:143d001c444cd$ab9aa640$a601280a@.phx.gbl...
>> I'm a new user of SQL Server.
>> What's the script to find out all indexes for tables and
>> views?
>> Thanks.
>
>.
>|||Hi,
Execute the below script in query analyzer
Use dbname
go
select substring(a.name,1,20) as Table_View_name,substring(b.name,1,20) as
Index_name,type as Object_type,indid
from sysobjects a, sysindexes b
where a.id=b.id
and type in ('U','V')
and indid between 1 and 254
-- If indid = 1 then Clustered index
-- indid >1 then Nonclustered index
Thanks
Hari
MCDBA
Julia" <anonymous@.discussions.microsoft.com> wrote in message
news:1443901c444d2$9074c850$a301280a@.phx.gbl...
> Thanks, is it possible to get all indexes for all tables
> and views in one script?
>
> >--Original Message--
> >Hi,
> >
> >sp_helpindex <table name or view name>
> >
> >You can also use the below statement to get all the
> information of the
> >object (including index).
> >
> >sp_help <table or view name>
> >
> >Thanks
> >Hari
> >MCDBA
> >
> >
> >"Julia" <KQD02@.YAHOO.COM> wrote in message
> >news:143d001c444cd$ab9aa640$a601280a@.phx.gbl...
> >> I'm a new user of SQL Server.
> >> What's the script to find out all indexes for tables and
> >> views?
> >> Thanks.
> >
> >
> >.
> >

find index for all tables and views in one script

Is it possible to get all indexes for all tables
and views in one script?Please don't multi-post; you have a thread going on elsewhere.
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
"Julia" <anonymous@.discussions.microsoft.com> wrote in message
news:146c101c444dc$362959b0$a001280a@.phx
.gbl...
> Is it possible to get all indexes for all tables
> and views in one script?
>|||Yup, you need to query sysobjects and sysindexes system tables.
Eric
Julia wrote:

> Is it possible to get all indexes for all tables
> and views in one script?
>
Eric Li
SQL DBA
MCDBA

find index for all tables and views in one script

Is it possible to get all indexes for all tables
and views in one script?Please don't multi-post; you have a thread going on elsewhere.
--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
"Julia" <anonymous@.discussions.microsoft.com> wrote in message
news:146c101c444dc$362959b0$a001280a@.phx.gbl...
> Is it possible to get all indexes for all tables
> and views in one script?
>|||Yup, you need to query sysobjects and sysindexes system tables.
Eric
Julia wrote:
> Is it possible to get all indexes for all tables
> and views in one script?
>
Eric Li
SQL DBA
MCDBA|||Please look my reply in your old post.
Thanks
Hari
MCDBA
"Julia" <anonymous@.discussions.microsoft.com> wrote in message
news:146c101c444dc$362959b0$a001280a@.phx.gbl...
> Is it possible to get all indexes for all tables
> and views in one script?
>

find index for all tables and views in one script

Is it possible to get all indexes for all tables
and views in one script?
Please don't multi-post; you have a thread going on elsewhere.
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
"Julia" <anonymous@.discussions.microsoft.com> wrote in message
news:146c101c444dc$362959b0$a001280a@.phx.gbl...
> Is it possible to get all indexes for all tables
> and views in one script?
>
|||Yup, you need to query sysobjects and sysindexes system tables.
Eric
Julia wrote:

> Is it possible to get all indexes for all tables
> and views in one script?
>
Eric Li
SQL DBA
MCDBA
|||Please look my reply in your old post.
Thanks
Hari
MCDBA
"Julia" <anonymous@.discussions.microsoft.com> wrote in message
news:146c101c444dc$362959b0$a001280a@.phx.gbl...
> Is it possible to get all indexes for all tables
> and views in one script?
>

Sunday, February 26, 2012

Find column names used in TSQL and Views

Is there are way to find out which View and Stored Procs contain a column
name or even a string? I am trying to rename a columnin a table from
Cust_name to CustName and want to find what views/stored procs will crash.
Thanks in advance,
Stewart Rogers
DataSort Software, L.C.
How do I find a stored procedure containing <text>?
http://databases.aspfaq.com/database/how-do-i-find-a-stored-procedure-containing-text.html
AMB
"Datasort" wrote:

> Is there are way to find out which View and Stored Procs contain a column
> name or even a string? I am trying to rename a columnin a table from
> Cust_name to CustName and want to find what views/stored procs will crash.
> Thanks in advance,
> --
> Stewart Rogers
> DataSort Software, L.C.
|||looks like AMesa has you covered for sprocs.
This query will get you the views:
use pubs
go
select v.name
from sys.columns c (nolock) inner join sys.views v (nolock) on v.object_id =
c.object_id
where c.name = 'title'
TheSQLGuru
President
Indicium Resources, Inc.
"Alejandro Mesa" <AlejandroMesa@.discussions.microsoft.com> wrote in message
news:A3083FBC-6C03-4A28-8B48-F21D8297D3C4@.microsoft.com...[vbcol=seagreen]
> How do I find a stored procedure containing <text>?
> http://databases.aspfaq.com/database/how-do-i-find-a-stored-procedure-containing-text.html
>
> AMB
>
> "Datasort" wrote:

Find column names used in TSQL and Views

Is there are way to find out which View and Stored Procs contain a column
name or even a string? I am trying to rename a columnin a table from
Cust_name to CustName and want to find what views/stored procs will crash.
Thanks in advance,
--
Stewart Rogers
DataSort Software, L.C.How do I find a stored procedure containing <text>?
http://databases.aspfaq.com/database/how-do-i-find-a-stored-procedure-containing-text.html
AMB
"Datasort" wrote:
> Is there are way to find out which View and Stored Procs contain a column
> name or even a string? I am trying to rename a columnin a table from
> Cust_name to CustName and want to find what views/stored procs will crash.
> Thanks in advance,
> --
> Stewart Rogers
> DataSort Software, L.C.|||looks like AMesa has you covered for sprocs.
This query will get you the views:
use pubs
go
select v.name
from sys.columns c (nolock) inner join sys.views v (nolock) on v.object_id =c.object_id
where c.name = 'title'
TheSQLGuru
President
Indicium Resources, Inc.
"Alejandro Mesa" <AlejandroMesa@.discussions.microsoft.com> wrote in message
news:A3083FBC-6C03-4A28-8B48-F21D8297D3C4@.microsoft.com...
> How do I find a stored procedure containing <text>?
> http://databases.aspfaq.com/database/how-do-i-find-a-stored-procedure-containing-text.html
>
> AMB
>
> "Datasort" wrote:
>> Is there are way to find out which View and Stored Procs contain a column
>> name or even a string? I am trying to rename a columnin a table from
>> Cust_name to CustName and want to find what views/stored procs will
>> crash.
>> Thanks in advance,
>> --
>> Stewart Rogers
>> DataSort Software, L.C.

find all triggers

How do I query the schema views (preferably) or sys tables to find all
triggers on my db?
tia
chrisDisplays the name of the table and the triggers:
Select c.name,a.name
From sysobjects a, sysdepends b, sysobjects c
Where a.id = b.id
And b.depid = c.id and a.type = 'TR' and c.type = 'U'
'U' defines tables, views are not incuded here, for that, leave out the last
part
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
--
"Chris" <Chris@.discussions.microsoft.com> schrieb im Newsbeitrag
news:BD6E22CA-A815-4CD1-AD15-590E6C168146@.microsoft.com...
> How do I query the schema views (preferably) or sys tables to find all
> triggers on my db?
> tia
> chris|||Select name TriggerName,
object_name(parent_obj) TableName
from sysobjects
Where type = 'TR'
"Chris" wrote:

> How do I query the schema views (preferably) or sys tables to find all
> triggers on my db?
> tia
> chris|||Hi Chris,
"Chris" <Chris@.discussions.microsoft.com> wrote in message
news:BD6E22CA-A815-4CD1-AD15-590E6C168146@.microsoft.com...
> How do I query the schema views (preferably) or sys tables to find all
> triggers on my db?
Try this:
select
trig.name as [Trigger Name],
tab.name as [Table Name],
case
when ObjectProperty( trig.id, 'ExecIsInsteadOfTrigger') = 1 then 'INSTEAD OF
' else 'FOR ' end
+ substring (
case when ObjectProperty( trig.id, 'ExecIsInsertTrigger') = 1 then ',
INSERT' else '' end +
case when ObjectProperty( trig.id, 'ExecIsUpdateTrigger') = 1 then ',
UPDATE' else '' end +
case when ObjectProperty( trig.id, 'ExecIsDeleteTrigger') = 1 then ',
DELETE' else '' end
, 3, 100) as [Trigger for]
from sysobjects as trig
inner join sysobjects as tab on tab.id = trig.parent_obj
where trig.type = 'TR'
order by tab.name
Or this:
select
object_name(parent_obj) as TableName,
name as TriggerName,
case(OBJECTPROPERTY(id, 'ExecIsTriggerDisabled'))
when 0 then 'YES'
when 1 then 'NO' end as Enable,
case(OBJECTPROPERTY(id, 'ExecIsInsertTrigger'))
when 0 then 'NO'
when 1 then 'YES' end as [Insert],
case(OBJECTPROPERTY(id, 'ExecIsUpdateTrigger'))
when 0 then 'NO'
when 1 then 'YES' end as [Update],
case(OBJECTPROPERTY(id, 'ExecIsDeleteTrigger'))
when 0 then 'NO'
when 1 then 'YES' end as [Delete],
case(OBJECTPROPERTY(id, 'ExecIsAfterTrigger'))
when 0 then 'Instead of'
when 1 then 'After' end as [Type],
crdate as CreationDate
from
sysobjects
where
type = 'TR'
order by
object_name(parent_obj), name

> tia
> chris
HTH,
Andrea - www.absistemi.it