Friday, March 23, 2012
how to find which object belongs to which File group
We have a DB in which we have created two file groups. Both are currently
Primary file group. what is the best way to find out which objects are in
which file group?
Thanks,
This doesn't make sense. "Both are currently Primary file group." Only one
filegroup can be the primary filegroup.
Tom
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada tom@.cips.ca
www.pinpub.com
"Moh" <mabbas@.Pier1.com> wrote in message
news:B93809BB-695B-4EED-9CE0-B3154B7D8301@.microsoft.com...
> Hi
> We have a DB in which we have created two file groups. Both are currently
> Primary file group. what is the best way to find out which objects are in
> which file group?
> Thanks,
>
|||I can mail you screen shot of EM where two files are listed as primary file
groups.
Moh
"Tom Moreau" wrote:
> This doesn't make sense. "Both are currently Primary file group." Only one
> filegroup can be the primary filegroup.
> --
> Tom
> ----
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Columnist, SQL Server Professional
> Toronto, ON Canada tom@.cips.ca
> www.pinpub.com
> "Moh" <mabbas@.Pier1.com> wrote in message
> news:B93809BB-695B-4EED-9CE0-B3154B7D8301@.microsoft.com...
>
>
|||That's not what you said. You said "we have created two file groups". Now,
you're saying you created two files. Which is it?
Tom
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada tom@.cips.ca
www.pinpub.com
"Moh" <mabbas@.Pier1.com> wrote in message
news:A0603CAB-EDF1-46BF-B449-D989432DF7DF@.microsoft.com...[vbcol=seagreen]
>I can mail you screen shot of EM where two files are listed as primary file
> groups.
> Moh
> "Tom Moreau" wrote:
|||By the way for your knowledge, you can have more than one files belongs to a
File group(Primary FG or any other). you can not have one file belongs to
more than one FG.
Does that mamke sense?
thx,
Moh
Sr DBA
Pier 1 Imports
mabbas@.Pier1.com
"Tom Moreau" wrote:
> This doesn't make sense. "Both are currently Primary file group." Only one
> filegroup can be the primary filegroup.
> --
> Tom
> ----
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Columnist, SQL Server Professional
> Toronto, ON Canada tom@.cips.ca
> www.pinpub.com
> "Moh" <mabbas@.Pier1.com> wrote in message
> news:B93809BB-695B-4EED-9CE0-B3154B7D8301@.microsoft.com...
>
>
|||I'm already aware of that. So, what exactly is the problem?
Tom
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada tom@.cips.ca
www.pinpub.com
"Moh" <mabbas@.Pier1.com> wrote in message
news:D6BCED88-53DB-4DA8-BC41-00E355065EF0@.microsoft.com...[vbcol=seagreen]
> By the way for your knowledge, you can have more than one files belongs to
> a
> File group(Primary FG or any other). you can not have one file belongs to
> more than one FG.
> Does that mamke sense?
> thx,
> Moh
> --
> Sr DBA
> Pier 1 Imports
> mabbas@.Pier1.com
>
> "Tom Moreau" wrote:
|||a filegroup is composed of one or more files
Objects are placed on filegroups and not files
If you wanted to know on which filegroup an object is placed, use sp_help
@.objectname
or the undocumented sp_objectfilegroup @.objid
If you wanted to know the list of all objects that belong to a filegroup
you can query sysindexes and group by the result by groupid
Med Bouchenafa
"Moh" <mabbas@.Pier1.com> a crit dans le message de news:
B93809BB-695B-4EED-9CE0-B3154B7D8301@.microsoft.com...
> Hi
> We have a DB in which we have created two file groups. Both are currently
> Primary file group. what is the best way to find out which objects are in
> which file group?
> Thanks,
>
|||Dear M Abbas,
From your 3 posts in this Response, it is clear that you need to improve in
following areas:
1. English Language Skills: There are both grammatical as well as spelling
mistakes in your posts. Example of Grammatical Mistake: ‘Both are currently
Primary file group’. Example of Spelling Mistake: ‘….mamke sense’.
2. Behavioural Skills: Tom Moreau didn’t make any wrong statements. It is
you who made wrong statement in the 1st post by saying ‘…we have created two
file groups. Both are currently Primary file group’. Still, you have
expressed anger in your 3rd post.
3. SQL Server Skills.
Remember, that the first person to benefit from these improvements will be
you. So choice is yours.
"Moh" wrote:
[vbcol=seagreen]
> By the way for your knowledge, you can have more than one files belongs to a
> File group(Primary FG or any other). you can not have one file belongs to
> more than one FG.
> Does that mamke sense?
> thx,
> Moh
> --
> Sr DBA
> Pier 1 Imports
> mabbas@.Pier1.com
>
> "Tom Moreau" wrote:
sql
how to find which object belongs to which File group
We have a DB in which we have created two file groups. Both are currently
Primary file group. what is the best way to find out which objects are in
which file group?
Thanks,This doesn't make sense. "Both are currently Primary file group." Only one
filegroup can be the primary filegroup.
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada tom@.cips.ca
www.pinpub.com
"Moh" <mabbas@.Pier1.com> wrote in message
news:B93809BB-695B-4EED-9CE0-B3154B7D8301@.microsoft.com...
> Hi
> We have a DB in which we have created two file groups. Both are currently
> Primary file group. what is the best way to find out which objects are in
> which file group?
> Thanks,
>|||I can mail you screen shot of EM where two files are listed as primary file
groups.
Moh
"Tom Moreau" wrote:
> This doesn't make sense. "Both are currently Primary file group." Only on
e
> filegroup can be the primary filegroup.
> --
> Tom
> ----
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Columnist, SQL Server Professional
> Toronto, ON Canada tom@.cips.ca
> www.pinpub.com
> "Moh" <mabbas@.Pier1.com> wrote in message
> news:B93809BB-695B-4EED-9CE0-B3154B7D8301@.microsoft.com...
>
>|||That's not what you said. You said "we have created two file groups". Now,
you're saying you created two files. Which is it?
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada tom@.cips.ca
www.pinpub.com
"Moh" <mabbas@.Pier1.com> wrote in message
news:A0603CAB-EDF1-46BF-B449-D989432DF7DF@.microsoft.com...[vbcol=seagreen]
>I can mail you screen shot of EM where two files are listed as primary file
> groups.
> Moh
> "Tom Moreau" wrote:
>|||By the way for your knowledge, you can have more than one files belongs to a
File group(Primary FG or any other). you can not have one file belongs to
more than one FG.
Does that mamke sense?
thx,
Moh
--
Sr DBA
Pier 1 Imports
mabbas@.Pier1.com
"Tom Moreau" wrote:
> This doesn't make sense. "Both are currently Primary file group." Only on
e
> filegroup can be the primary filegroup.
> --
> Tom
> ----
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Columnist, SQL Server Professional
> Toronto, ON Canada tom@.cips.ca
> www.pinpub.com
> "Moh" <mabbas@.Pier1.com> wrote in message
> news:B93809BB-695B-4EED-9CE0-B3154B7D8301@.microsoft.com...
>
>|||I'm already aware of that. So, what exactly is the problem?
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada tom@.cips.ca
www.pinpub.com
"Moh" <mabbas@.Pier1.com> wrote in message
news:D6BCED88-53DB-4DA8-BC41-00E355065EF0@.microsoft.com...[vbcol=seagreen]
> By the way for your knowledge, you can have more than one files belongs to
> a
> File group(Primary FG or any other). you can not have one file belongs to
> more than one FG.
> Does that mamke sense?
> thx,
> Moh
> --
> Sr DBA
> Pier 1 Imports
> mabbas@.Pier1.com
>
> "Tom Moreau" wrote:
>|||a filegroup is composed of one or more files
Objects are placed on filegroups and not files
If you wanted to know on which filegroup an object is placed, use sp_help
@.objectname
or the undocumented sp_objectfilegroup @.objid
If you wanted to know the list of all objects that belong to a filegroup
you can query sysindexes and group by the result by groupid
Med Bouchenafa
"Moh" <mabbas@.Pier1.com> a crit dans le message de news:
B93809BB-695B-4EED-9CE0-B3154B7D8301@.microsoft.com...
> Hi
> We have a DB in which we have created two file groups. Both are currently
> Primary file group. what is the best way to find out which objects are in
> which file group?
> Thanks,
>|||Dear M Abbas,
From your 3 posts in this Response, it is clear that you need to improve in
following areas:
1. English Language Skills: There are both grammatical as well as spelling
mistakes in your posts. Example of Grammatical Mistake: ‘Both are currentl
y
Primary file group’. Example of Spelling Mistake: ‘….mamke sense’.
2. Behavioural Skills: Tom Moreau didn’t make any wrong statements. It is
you who made wrong statement in the 1st post by saying ‘…we have created
two
file groups. Both are currently Primary file group’. Still, you have
expressed anger in your 3rd post.
3. SQL Server Skills.
Remember, that the first person to benefit from these improvements will be
you. So choice is yours.
"Moh" wrote:
[vbcol=seagreen]
> By the way for your knowledge, you can have more than one files belongs to
a
> File group(Primary FG or any other). you can not have one file belongs to
> more than one FG.
> Does that mamke sense?
> thx,
> Moh
> --
> Sr DBA
> Pier 1 Imports
> mabbas@.Pier1.com
>
> "Tom Moreau" wrote:
>
how to find which object belongs to which File group
We have a DB in which we have created two file groups. Both are currently
Primary file group. what is the best way to find out which objects are in
which file group?
Thanks,This doesn't make sense. "Both are currently Primary file group." Only one
filegroup can be the primary filegroup.
--
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada tom@.cips.ca
www.pinpub.com
"Moh" <mabbas@.Pier1.com> wrote in message
news:B93809BB-695B-4EED-9CE0-B3154B7D8301@.microsoft.com...
> Hi
> We have a DB in which we have created two file groups. Both are currently
> Primary file group. what is the best way to find out which objects are in
> which file group?
> Thanks,
>|||I can mail you screen shot of EM where two files are listed as primary file
groups.
Moh
"Tom Moreau" wrote:
> This doesn't make sense. "Both are currently Primary file group." Only one
> filegroup can be the primary filegroup.
> --
> Tom
> ----
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Columnist, SQL Server Professional
> Toronto, ON Canada tom@.cips.ca
> www.pinpub.com
> "Moh" <mabbas@.Pier1.com> wrote in message
> news:B93809BB-695B-4EED-9CE0-B3154B7D8301@.microsoft.com...
> > Hi
> > We have a DB in which we have created two file groups. Both are currently
> > Primary file group. what is the best way to find out which objects are in
> > which file group?
> >
> > Thanks,
> >
> >
>
>|||That's not what you said. You said "we have created two file groups". Now,
you're saying you created two files. Which is it?
--
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada tom@.cips.ca
www.pinpub.com
"Moh" <mabbas@.Pier1.com> wrote in message
news:A0603CAB-EDF1-46BF-B449-D989432DF7DF@.microsoft.com...
>I can mail you screen shot of EM where two files are listed as primary file
> groups.
> Moh
> "Tom Moreau" wrote:
>> This doesn't make sense. "Both are currently Primary file group." Only
>> one
>> filegroup can be the primary filegroup.
>> --
>> Tom
>> ----
>> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
>> SQL Server MVP
>> Columnist, SQL Server Professional
>> Toronto, ON Canada tom@.cips.ca
>> www.pinpub.com
>> "Moh" <mabbas@.Pier1.com> wrote in message
>> news:B93809BB-695B-4EED-9CE0-B3154B7D8301@.microsoft.com...
>> > Hi
>> > We have a DB in which we have created two file groups. Both are
>> > currently
>> > Primary file group. what is the best way to find out which objects are
>> > in
>> > which file group?
>> >
>> > Thanks,
>> >
>> >
>>|||By the way for your knowledge, you can have more than one files belongs to a
File group(Primary FG or any other). you can not have one file belongs to
more than one FG.
Does that mamke sense?
thx,
Moh
--
Sr DBA
Pier 1 Imports
mabbas@.Pier1.com
"Tom Moreau" wrote:
> This doesn't make sense. "Both are currently Primary file group." Only one
> filegroup can be the primary filegroup.
> --
> Tom
> ----
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Columnist, SQL Server Professional
> Toronto, ON Canada tom@.cips.ca
> www.pinpub.com
> "Moh" <mabbas@.Pier1.com> wrote in message
> news:B93809BB-695B-4EED-9CE0-B3154B7D8301@.microsoft.com...
> > Hi
> > We have a DB in which we have created two file groups. Both are currently
> > Primary file group. what is the best way to find out which objects are in
> > which file group?
> >
> > Thanks,
> >
> >
>
>|||I'm already aware of that. So, what exactly is the problem?
--
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada tom@.cips.ca
www.pinpub.com
"Moh" <mabbas@.Pier1.com> wrote in message
news:D6BCED88-53DB-4DA8-BC41-00E355065EF0@.microsoft.com...
> By the way for your knowledge, you can have more than one files belongs to
> a
> File group(Primary FG or any other). you can not have one file belongs to
> more than one FG.
> Does that mamke sense?
> thx,
> Moh
> --
> Sr DBA
> Pier 1 Imports
> mabbas@.Pier1.com
>
> "Tom Moreau" wrote:
>> This doesn't make sense. "Both are currently Primary file group." Only
>> one
>> filegroup can be the primary filegroup.
>> --
>> Tom
>> ----
>> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
>> SQL Server MVP
>> Columnist, SQL Server Professional
>> Toronto, ON Canada tom@.cips.ca
>> www.pinpub.com
>> "Moh" <mabbas@.Pier1.com> wrote in message
>> news:B93809BB-695B-4EED-9CE0-B3154B7D8301@.microsoft.com...
>> > Hi
>> > We have a DB in which we have created two file groups. Both are
>> > currently
>> > Primary file group. what is the best way to find out which objects are
>> > in
>> > which file group?
>> >
>> > Thanks,
>> >
>> >
>>|||a filegroup is composed of one or more files
Objects are placed on filegroups and not files
If you wanted to know on which filegroup an object is placed, use sp_help
@.objectname
or the undocumented sp_objectfilegroup @.objid
If you wanted to know the list of all objects that belong to a filegroup
you can query sysindexes and group by the result by groupid
Med Bouchenafa
"Moh" <mabbas@.Pier1.com> a écrit dans le message de news:
B93809BB-695B-4EED-9CE0-B3154B7D8301@.microsoft.com...
> Hi
> We have a DB in which we have created two file groups. Both are currently
> Primary file group. what is the best way to find out which objects are in
> which file group?
> Thanks,
>|||Dear M Abbas,
From your 3 posts in this Response, it is clear that you need to improve in
following areas:
1. English Language Skills: There are both grammatical as well as spelling
mistakes in your posts. Example of Grammatical Mistake: â'Both are currently
Primary file groupâ'. Example of Spelling Mistake: â'â?¦.mamke senseâ'.
2. Behavioural Skills: Tom Moreau didnâ't make any wrong statements. It is
you who made wrong statement in the 1st post by saying â'â?¦we have created two
file groups. Both are currently Primary file groupâ'. Still, you have
expressed anger in your 3rd post.
3. SQL Server Skills.
Remember, that the first person to benefit from these improvements will be
you. So choice is yours.
"Moh" wrote:
> By the way for your knowledge, you can have more than one files belongs to a
> File group(Primary FG or any other). you can not have one file belongs to
> more than one FG.
> Does that mamke sense?
> thx,
> Moh
> --
> Sr DBA
> Pier 1 Imports
> mabbas@.Pier1.com
>
> "Tom Moreau" wrote:
> > This doesn't make sense. "Both are currently Primary file group." Only one
> > filegroup can be the primary filegroup.
> >
> > --
> > Tom
> >
> > ----
> > Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> > SQL Server MVP
> > Columnist, SQL Server Professional
> > Toronto, ON Canada tom@.cips.ca
> > www.pinpub.com
> >
> > "Moh" <mabbas@.Pier1.com> wrote in message
> > news:B93809BB-695B-4EED-9CE0-B3154B7D8301@.microsoft.com...
> > > Hi
> > > We have a DB in which we have created two file groups. Both are currently
> > > Primary file group. what is the best way to find out which objects are in
> > > which file group?
> > >
> > > Thanks,
How to find unused Objects?
Is there a way in SQL I can tell when the last time a stored procedure was run or a table was accessed? I know there are a lot of objects in my system that are probably no longer being used but what is the best way to go about identifing these objects?
Gk
That is not going to be a 'simple' process. There is nothing inherrent in SQL Server that will give you that information with certainty.
You could set up a Profiler trace to capture the procedure/function/view/table name over time.
There are some Third party products that will follow the dependency trees, and also track usage. Check Tibor's list.
The process I follow is this:
When I identify an object that is a removal candidate:
All Stored Procedures/Functions/views/Tables that have been created in a database for solely administrative purposes are, in SQL 2000 named [dbs_, dbf_, dbv_, db_] and in SQL 2005, added to the [Admin] schema. I have a 'home-grown' .NET tool that will cycle through the source control store, examining application code, compiling a list of command.text statements, Since my practice is to require the use of stored procedures for all data access, the command.text is a list of Stored Procedures. I then check object dependencies against the list. I now have my 'first pass' candidate list. I first rename the candidate object (add 'x' to the beginning and they all sort to the bottom of the list). If something then 'breaks', it is very quick to change the name back and restore functionality. I leave the renamed objects for 3-6 months before final deletion. (Some things may be rarely used, but they may be for an 'important' process -such as reporting.) If it is obvious that the object is for a reporting process, I may leave it for a year -there are annual reports... When an object is finally removed, I script it out and store the script in an object archive. (Who knows, perhaps that object had some 'nice' code in it that I can refer to later.)sqlMonday, March 19, 2012
How to find owner of objects
created and change all of them to be owned by sa. I have recently been
getting a randomly occuring error in some job execution due to SQL not being
able to verify if an object owner really has access.
This the notification message I receive:
STATUS: Failed
MESSAGES: The job failed. Unable to determine if the owner (NCN\dbohannon)
of job Restore DukeEDI_TLog has server access (reason: Could not obtain
information about Windows NT group/user 'NCN\dbohannon'. [SQLSTATE 42000]
(Error 8198)).
I don't understand what would cause this since my account is a sysadmin and
it is the same security that these jobs have always run under.
Thanks in advance,
DeborahThe problem you're running into is not actually a SQL issue rather a error
returning information from the DC.
See the following kb article;
241643 PRB: 8198 Error Message Returned from Job Owned by Windows NT
http://support.microsoft.com/?id=241643
Changing the job ownership to a standard SQL account forces a change in
code path, which doesn't require a query to the DC.
Each job can be changed to make the job owner someone other than the
domain\user in Enterprise Manager.
Thanks,
Kevin McDonnell
Microsoft Corporation
This posting is provided AS IS with no warranties, and confers no rights.|||Can you please tell me why this error would be intermittent? The scheduled
job has run successfully for weeks, and then I get this error. I then ran
the job again and it ran with no problem. I'm thinking if it were truly an
account problem then it would be so every time it is run.
Plus, the server it is running on was never anything besides Windows 2000
Server.
Thanks
"Kevin McDonnell [MSFT]" <kevmc@.online.microsoft.com> wrote in message
news:vvkveL72DHA.2588@.cpmsftngxa08.phx.gbl...
quote:|||What I have seen in the past is that the calls we make to the Domain
> The problem you're running into is not actually a SQL issue rather a error
> returning information from the DC.
> See the following kb article;
> 241643 PRB: 8198 Error Message Returned from Job Owned by Windows NT
> http://support.microsoft.com/?id=241643
> Changing the job ownership to a standard SQL account forces a change in
> code path, which doesn't require a query to the DC.
> Each job can be changed to make the job owner someone other than the
> domain\user in Enterprise Manager.
>
> Thanks,
> Kevin McDonnell
> Microsoft Corporation
> This posting is provided AS IS with no warranties, and confers no rights.
>
>
Controller to enumerate the groups may fail intermittantly. So, it is not
the OS that SQL Server is running on, rather the communication between SQL
and the DC. So, if the DC is having problems or is busy, the query may
start to fail.
Thanks,
Kevin McDonnell
Microsoft Corporation
This posting is provided AS IS with no warranties, and confers no rights.
Friday, March 9, 2012
How to find out invalid Objects in sql server databases
Hi,
How to find out invalid objects in sql server databases
What do u mean invalid object?How to find objects by owner
the application itself. So I have a bunch of views created by a user who I
have to delete but I can't do it because he is owning objects.
Can I write a query to list al the objects owned by this user?
Regardsselect name from sysobjects where uid = user_id('NameOfOwner')
"Zekske" wrote:
> I have an application wich generates database objects (mostly views) within
> the application itself. So I have a bunch of views created by a user who I
> have to delete but I can't do it because he is owning objects.
> Can I write a query to list al the objects owned by this user?
> Regards|||You could use the inbuilt views - just change 'dbo' to your user...
-- tables and views
select * from information_schema.tables
where table_schema = 'dbo'
-- stored procs and functions
select routine_name from information_schema.routines
where routine_schema = 'dbo'
Cheers,
Paul Ibison SQL Server MVP, www.replicationanswers.com
(recommended sql server 2000 replication book:
http://www.nwsu.com/0974973602p.html)
How to find objects by owner
the application itself. So I have a bunch of views created by a user who I
have to delete but I can't do it because he is owning objects.
Can I write a query to list al the objects owned by this user?
Regards
select name from sysobjects where uid = user_id('NameOfOwner')
"Zekske" wrote:
> I have an application wich generates database objects (mostly views) within
> the application itself. So I have a bunch of views created by a user who I
> have to delete but I can't do it because he is owning objects.
> Can I write a query to list al the objects owned by this user?
> Regards
|||You could use the inbuilt views - just change 'dbo' to your user...
-- tables and views
select * from information_schema.tables
where table_schema = 'dbo'
-- stored procs and functions
select routine_name from information_schema.routines
where routine_schema = 'dbo'
Cheers,
Paul Ibison SQL Server MVP, www.replicationanswers.com
(recommended sql server 2000 replication book:
http://www.nwsu.com/0974973602p.html)
How to find objects by owner
the application itself. So I have a bunch of views created by a user who I
have to delete but I can't do it because he is owning objects.
Can I write a query to list al the objects owned by this user?
Regardsselect name from sysobjects where uid = user_id('NameOfOwner')
"Zekske" wrote:
> I have an application wich generates database objects (mostly views) withi
n
> the application itself. So I have a bunch of views created by a user who I
> have to delete but I can't do it because he is owning objects.
> Can I write a query to list al the objects owned by this user?
> Regards|||You could use the inbuilt views - just change 'dbo' to your user...
-- tables and views
select * from information_schema.tables
where table_schema = 'dbo'
-- stored procs and functions
select routine_name from information_schema.routines
where routine_schema = 'dbo'
Cheers,
Paul Ibison SQL Server MVP, www.replicationanswers.com
(recommended sql server 2000 replication book:
http://www.nwsu.com/0974973602p.html)
Wednesday, March 7, 2012
how to find invalid objects --After DDL changes
Hi
I have a SQL Server 2005 database running. When I run some ddl changes, I want to find all the procs/objects that get invalidated because of object not found error.....
Is there any way that I can look up in sysdepends or other tables to find information about this.
Regards
Imtiaz
You can query the system view sys.syscomments for any procedures or functions that reference the objects. The text of each is stored in sys.syscomments.text.
How to find inactive objects..
SQL 2005 Enterprise Edition SP 2
Thanks in advance.
Kay
You could start by running sp_depends for each table in the database. Unfortunately sp_depends is not always 100% accurate, and it will not pick up things like inline SQL being called from applications, but it is a start.
The DMV query below can also help find unused tables.
-- Unused tables & indexes. Tables have index_id’s of either 0 = Heap table or 1 = Clustered Index
DECLARE @.dbid int
SELECT @.dbid =db_id()
SELECT objectname=object_name(i.object_id), indexname=i.name, i.index_id
FROMsys.indexes i,sys.objectsAS o
WHEREobjectproperty(o.object_id,'IsUserTable')= 1
AND i.index_id NOTIN(SELECT s.index_id
FROMsys.dm_db_index_usage_statsAS s
WHERE s.object_id=i.object_id
AND i.index_id=s.index_id
AND database_id = @.dbid )
AND o.object_id= i.object_id
ORDERBY objectname,i.index_id,indexname ASC
How to find inactive objects
I am trying to find any stored procedures or tables that have not been used in the last 2 months or so. Can anyone recommend me a good way to do this?
SQL 2005 Enterprise Edition SP 2
Thanks in advance.
Kay
There is a dynamic management view that will give you what you want since the last restart:
select object_name(i.object_id) as object_name
, case when i.is_unique = 1 then 'UNIQUE ' else '' end + i.type_desc as index_type
, i.object_id
, i.name as index_name
, i.index_id
, coalesce(user_seeks,0) as user_seeks
, coalesce(user_scans,0) as user_scans
, coalesce(user_lookups,0) as user_lookups
, coalesce(user_updates,0) as user_updates
from sys.indexes i
left outer join sys.dm_db_index_usage_stats s
on i.object_id = s.object_id
and i.index_id = s.index_id
and database_id = db_id()
where objectproperty(i.object_id , 'IsUserTable') = 1
and i.index_id in (1,0) --clustered index or heap
order by user_seeks + user_scans + user_lookups + user_updates asc
It tells how many times the index has been accessed in queries, changed, etc.
Friday, February 24, 2012
How to find Dependent/Referenced Objects of a Stored Procedure?
Could anybody tell me how can I find all the database objects that are used in /referenced by/called by/dependent on a given stored procedure? In other words, I am looking for something like a stored procedure or a function that takes as input the name of a stored procedure and outputs all the names of the tables, functions, procedures, cursors and etc. database objects that are used in that procedure. Could you please give me suggestions or possible answers for this?
Thanks a lot for your time.
Regards,
-Ram.Sure, take this query here:
Select OBJECT_NAME(id),OBJECT_NAME(depid) from sysdepends
WHERE id = OBJECT_ID('YourPrcoedurename')
HTH, Jens K. Suessmeyer.
http://www.sqlserver2005.de
|||Thanks Jens.How to find dependent objects?
Is there any way to find out all the dependent objects in sql server?
Sp_depends doesnt do it sysdepends table corruption.
Any thoughts?
Thanks
> Is there any way to find out all the dependent objects in sql server?
> Sp_depends doesnt do it sysdepends table corruption.
You might want to check a 3rd party tol, for example
http://www.red-gate.com/sql/more/sysdepends.htm.
Dejan Sarka, SQL Server MVP
Associate Mentor
www.SolidQualityLearning.com
How to find dependent objects?
Is there any way to find out all the dependent objects in sql server?
Sp_depends doesnt do it sysdepends table corruption.
Any thoughts?
Thanks> Is there any way to find out all the dependent objects in sql server?
> Sp_depends doesnt do it sysdepends table corruption.
You might want to check a 3rd party tol, for example
http://www.red-gate.com/sql/more/sysdepends.htm.
Dejan Sarka, SQL Server MVP
Associate Mentor
www.SolidQualityLearning.com
How to find dependent objects?
Is there any way to find out all the dependent objects in sql server?
Sp_depends doesnt do it sysdepends table corruption.
Any thoughts?
Thanks> Is there any way to find out all the dependent objects in sql server?
> Sp_depends doesnt do it sysdepends table corruption.
You might want to check a 3rd party tol, for example
http://www.red-gate.com/sql/more/sysdepends.htm.
--
Dejan Sarka, SQL Server MVP
Associate Mentor
www.SolidQualityLearning.com
Sunday, February 19, 2012
How to filter our system objects from the list
Server database (this is taken from VB6 code):
lstrSQL = "select name, refdate from dbo.sysobjects where " &
lstrFilter & " order by name"
I apply filter to narrow the results to particular type, for example
for procedures:
lstrFilter = "OBJECTPROPERTY(id, N'IsProcedure') = 1"
For functions:
lstrFilter = "OBJECTPROPERTY(id, N'IsInlineFunction') = 1
or OBJECTPROPERTY(id, N'IsScalarFunction') = 1 or OBJECTPROPERTY(id,
N'IsTableFunction') = 1"
etc.
My question is: how can I filter out the objects created by the system
(I want only the objects created by the users to be left)?
Ideally, I'd like the solution to work in SQL Server 2005 and in the
older versions.
TIA
Dariusz Dziewialtowski.Use the xtype column to exclude the objects you don't want to show:
xtype: Object type. Can be one of these object types:
C = CHECK constraint
D = Default or DEFAULT constraint
F = FOREIGN KEY constraint
L = Log
FN = Scalar function
IF = Inlined table-function
P = Stored procedure
PK = PRIMARY KEY constraint (type is K)
RF = Replication filter stored procedure
S = System table
TF = Table function
TR = Trigger
U = User table
UQ = UNIQUE constraint (type is K)
V = View
X = Extended stored procedure
"dariusz.dziewialtowski@.gmail.com" wrote:
> I'm using following statement to get the list of objects in given SQL
> Server database (this is taken from VB6 code):
> lstrSQL = "select name, refdate from dbo.sysobjects where " &
> lstrFilter & " order by name"
> I apply filter to narrow the results to particular type, for example
> for procedures:
> lstrFilter = "OBJECTPROPERTY(id, N'IsProcedure') = 1"
> For functions:
> lstrFilter = "OBJECTPROPERTY(id, N'IsInlineFunction') = 1
> or OBJECTPROPERTY(id, N'IsScalarFunction') = 1 or OBJECTPROPERTY(id,
> N'IsTableFunction') = 1"
> etc.
> My question is: how can I filter out the objects created by the system
> (I want only the objects created by the users to be left)?
> Ideally, I'd like the solution to work in SQL Server 2005 and in the
> older versions.
> TIA
> Dariusz Dziewialtowski.
>|||select *
from sysobjects
where xtype <> 'S'
"Edgardo Valdez, MCSD, MCDBA" wrote:
> Use the xtype column to exclude the objects you don't want to show:
> xtype: Object type. Can be one of these object types:
> C = CHECK constraint
> D = Default or DEFAULT constraint
> F = FOREIGN KEY constraint
> L = Log
> FN = Scalar function
> IF = Inlined table-function
> P = Stored procedure
> PK = PRIMARY KEY constraint (type is K)
> RF = Replication filter stored procedure
> S = System table
> TF = Table function
> TR = Trigger
> U = User table
> UQ = UNIQUE constraint (type is K)
> V = View
> X = Extended stored procedure
>
> "dariusz.dziewialtowski@.gmail.com" wrote:
>|||Try,
...
and objectproperty([id], 'IsMSShipped') = 0
AMB
"dariusz.dziewialtowski@.gmail.com" wrote:
> I'm using following statement to get the list of objects in given SQL
> Server database (this is taken from VB6 code):
> lstrSQL = "select name, refdate from dbo.sysobjects where " &
> lstrFilter & " order by name"
> I apply filter to narrow the results to particular type, for example
> for procedures:
> lstrFilter = "OBJECTPROPERTY(id, N'IsProcedure') = 1"
> For functions:
> lstrFilter = "OBJECTPROPERTY(id, N'IsInlineFunction') = 1
> or OBJECTPROPERTY(id, N'IsScalarFunction') = 1 or OBJECTPROPERTY(id,
> N'IsTableFunction') = 1"
> etc.
> My question is: how can I filter out the objects created by the system
> (I want only the objects created by the users to be left)?
> Ideally, I'd like the solution to work in SQL Server 2005 and in the
> older versions.
> TIA
> Dariusz Dziewialtowski.
>|||Use the IsMSShipped object property|||Edgardo, Alejandro, Scott
Thank you for your so quick responses!
I was thinking about using IsMSShipped in the past but I was afraid
that it wouldn't work right - for example: the whole Northwind database
is shipped by Microsoft - would the flag IsMSShipped be set to TRUE for
all objects in that database in that case?
Hmm, I have to test it actually...
Again - thanks a lot for your help!
Dariusz Dziewialtowski.|||That's a good point.
Actually, the IsMSShipped property is only set for those objects that
someone set it on for. Anyone can mark an object so that the IsMSShipped bit
is true by running sp_MS_marksystemobject.
So there is really no way to know for sure what is shipped by MS and what
isn't. You'll have to come up with another way of determining which objects
you want to see and which you don't.
HTH
Kalen Delaney, SQL Server MVP
www.solidqualitylearning.com
<dariusz.dziewialtowski@.gmail.com> wrote in message
news:1144681248.829348.140770@.i40g2000cwc.googlegroups.com...
> Edgardo, Alejandro, Scott
> Thank you for your so quick responses!
> I was thinking about using IsMSShipped in the past but I was afraid
> that it wouldn't work right - for example: the whole Northwind database
> is shipped by Microsoft - would the flag IsMSShipped be set to TRUE for
> all objects in that database in that case?
> Hmm, I have to test it actually...
> Again - thanks a lot for your help!
>
> Dariusz Dziewialtowski.
>|||Kalen,
Thanks a lot for your explanation!
Dariusz Dziewialtowski