 |
|
 |
|
Next: Manager/ment Server Status Check
|
| Author |
Message |
External

Since: Jan 14, 2008 Posts: 14
|
(Msg. 1) Posted: Mon Nov 24, 2008 10:03 am
Post subject: List of Tables in a FileGroup Archived from groups: microsoft>public>sqlserver>server (more info?)
|
|
|
|
|
| Back to top |
|
 |  |
External

Since: Jan 10, 2008 Posts: 608
|
(Msg. 2) Posted: Mon Nov 24, 2008 1:59 pm
Post subject: Re: List of Tables in a FileGroup [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
rgn,
Almost, but not quite. What actually exists in filegroups are indexes. Of
course, index_id=1 is the clustered index or index_id=1 is the heap, either
of which include the leaf (data) pages. (Every index for a table could be
on a different filegroup.)
So, here is a start:
SELECT OBJECT_NAME(i.id) AS ObjectName,
i.name AS IndexName, ds.data_space_id, ds.type
FROM sys.indexes i
JOIN sys.data_spaces ds
ON i.data_space_id = ds.data_space_id
RLF
"rgn" wrote in message
> Is there a way to get a list of all the tables in a particular File Group.
>
> rgn >> Stay informed about: List of Tables in a FileGroup |
|
| Back to top |
|
 |  |
External

Since: Oct 27, 2003 Posts: 290
|
(Msg. 3) Posted: Mon Nov 24, 2008 1:59 pm
Post subject: Re: List of Tables in a FileGroup [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
I guess we could play semantic games, but a heap is not an index, even
though there is a row for it in sys.indexes.
And, as I'm sure Russell knows (it was probably just his fingers that didn't
know) the index_id for a heap is 0.
A heap has no concept of leaf pages, it just has the data.
The thing that I would have said 'almost but not quite' about, would be if
the table is partitioned. Then the entire table may not be on a single
filegroup. In the code below, data_space_id may not map to a filegroup, it
may map to a partition scheme, which can be composed of hundred of different
filegroups.
--
HTH
Kalen Delaney, SQL Server MVP
www.InsideSQLServer.com
www.SQLTuners.com
"Russell Fields" wrote in message
> rgn,
>
> Almost, but not quite. What actually exists in filegroups are indexes.
> Of course, index_id=1 is the clustered index or index_id=1 is the heap,
> either of which include the leaf (data) pages. (Every index for a table
> could be on a different filegroup.)
>
> So, here is a start:
>
> SELECT OBJECT_NAME(i.id) AS ObjectName,
> i.name AS IndexName, ds.data_space_id, ds.type
> FROM sys.indexes i
> JOIN sys.data_spaces ds
> ON i.data_space_id = ds.data_space_id
>
>
> RLF
>
>
> "rgn" wrote in message
>
>> Is there a way to get a list of all the tables in a particular File
>> Group.
>>
>> rgn
> >> Stay informed about: List of Tables in a FileGroup |
|
| Back to top |
|
 |  |
External

Since: Jan 10, 2008 Posts: 608
|
(Msg. 4) Posted: Mon Nov 24, 2008 2:53 pm
Post subject: Re: List of Tables in a FileGroup [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Kalen, Thanks both for correcting my mistyping and for expanding the
explanation. - RLF
"Kalen Delaney" wrote in message
>I guess we could play semantic games, but a heap is not an index, even
>though there is a row for it in sys.indexes.
> And, as I'm sure Russell knows (it was probably just his fingers that
> didn't know) the index_id for a heap is 0.
> A heap has no concept of leaf pages, it just has the data.
>
> The thing that I would have said 'almost but not quite' about, would be if
> the table is partitioned. Then the entire table may not be on a single
> filegroup. In the code below, data_space_id may not map to a filegroup, it
> may map to a partition scheme, which can be composed of hundred of
> different filegroups.
>
> --
> HTH
> Kalen Delaney, SQL Server MVP
> www.InsideSQLServer.com
> www.SQLTuners.com
>
>
> "Russell Fields" wrote in message
>
>> rgn,
>>
>> Almost, but not quite. What actually exists in filegroups are indexes.
>> Of course, index_id=1 is the clustered index or index_id=1 is the heap,
>> either of which include the leaf (data) pages. (Every index for a table
>> could be on a different filegroup.)
>>
>> So, here is a start:
>>
>> SELECT OBJECT_NAME(i.id) AS ObjectName,
>> i.name AS IndexName, ds.data_space_id, ds.type
>> FROM sys.indexes i
>> JOIN sys.data_spaces ds
>> ON i.data_space_id = ds.data_space_id
>>
>>
>> RLF
>>
>>
>> "rgn" wrote in message
>>
>>> Is there a way to get a list of all the tables in a particular File
>>> Group.
>>>
>>> rgn
>>
>
> >> Stay informed about: List of Tables in a FileGroup |
|
| Back to top |
|
 |  |
External

Since: Oct 27, 2003 Posts: 290
|
(Msg. 5) Posted: Mon Nov 24, 2008 2:53 pm
Post subject: Re: List of Tables in a FileGroup [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
It's just so rare that I find anything that needs correcting in your
explanations ...
--
HTH
Kalen Delaney, SQL Server MVP
www.InsideSQLServer.com
www.SQLTuners.com
"Russell Fields" wrote in message
> Kalen, Thanks both for correcting my mistyping and for expanding the
> explanation. - RLF
>
> "Kalen Delaney" wrote in message
>
>>I guess we could play semantic games, but a heap is not an index, even
>>though there is a row for it in sys.indexes.
>> And, as I'm sure Russell knows (it was probably just his fingers that
>> didn't know) the index_id for a heap is 0.
>> A heap has no concept of leaf pages, it just has the data.
>>
>> The thing that I would have said 'almost but not quite' about, would be
>> if the table is partitioned. Then the entire table may not be on a single
>> filegroup. In the code below, data_space_id may not map to a filegroup,
>> it may map to a partition scheme, which can be composed of hundred of
>> different filegroups.
>>
>> --
>> HTH
>> Kalen Delaney, SQL Server MVP
>> www.InsideSQLServer.com
>> www.SQLTuners.com
>>
>>
>> "Russell Fields" wrote in message
>>
>>> rgn,
>>>
>>> Almost, but not quite. What actually exists in filegroups are indexes.
>>> Of course, index_id=1 is the clustered index or index_id=1 is the heap,
>>> either of which include the leaf (data) pages. (Every index for a
>>> table could be on a different filegroup.)
>>>
>>> So, here is a start:
>>>
>>> SELECT OBJECT_NAME(i.id) AS ObjectName,
>>> i.name AS IndexName, ds.data_space_id, ds.type
>>> FROM sys.indexes i
>>> JOIN sys.data_spaces ds
>>> ON i.data_space_id = ds.data_space_id
>>>
>>>
>>> RLF
>>>
>>>
>>> "rgn" wrote in message
>>>
>>>> Is there a way to get a list of all the tables in a particular File
>>>> Group.
>>>>
>>>> rgn
>>>
>>
>>
> >> Stay informed about: List of Tables in a FileGroup |
|
| Back to top |
|
 |  |
External

Since: Nov 13, 2008 Posts: 49
|
(Msg. 6) Posted: Mon Nov 24, 2008 11:25 pm
Post subject: Re: List of Tables in a FileGroup [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Hi Rgn,
Here is a script that I got from Internet ...
/*==================================================================================
NAME: Get extended filegroup info for all DB tables and views
(location of data pages, indexes, etc)
DESCRIPTION: This script returns the following extended filegroup
info
For all DB tables and indexed views:
1. The table (or view) name
2. The type of the object (i.e., table or view)
3. The filegroup location of the clustered index (when
exists), non-clustered indexes, data pages (if other
than the clustered index), and the NTEXT/TEXT/IMAGE
column data.
4. The indid (from sysindexes) that corresponds to
the attributes listed in (3).
5. The filegroup name and id on which the items listed
in (3) are located.
USER PARAMETERS: NA
RESULTSET: TableOrViewName, [Table/View], AttributeName,
AttributeType,
AttributeIndid, FileGroupName, FileGroupID
RESULTSET SORT: TableOrViewName, AttributeIndid
USING TABLES/VIEWS: INFORMATION_SCHEMA.TABLES
sysindexes
REVISIONS
DATE DEVELOPER DESCRIPTION OF REVISION VERSION
========= =============== =================================
===========
04/18/2005 Omri Bahat Initial release 1.00
==================================================================================
Copyright © SQL Farms Solutions, www.sqlfarms.com. All rights reserved.
This code may be used at no charge as long as this copyright notice is not
removed.
==================================================================================*/
-- Get all DB tables and views filegroup info
SET NOCOUNT ON
-- This table will hold the collected filegroup information
IF OBJECT_ID('tempdb..#tblFileGroupInfo', 'U') IS NOT NULL
DROP TABLE #tblFileGroupInfo
CREATE TABLE #tblFileGroupInfo(
TableOrViewName NVARCHAR(128),
[Table/View] VARCHAR(16),
AttributeName NVARCHAR(128),
AttributeType VARCHAR(128),
AttributeIndid INT,
FileGroupName NVARCHAR(128),
FileGroupID INT)
-- Get the file group information for all indexes of all tables and indexed
views
-- on the database. Note that auto-statistics created by SQL server are
excluded,
-- since they are hardly of interest.
INSERT INTO #tblFileGroupInfo(
TableOrViewName,
[Table/View],
AttributeName,
AttributeType,
AttributeIndid,
FileGroupName,
FileGroupID)
SELECT a.TABLE_NAME,
CASE WHEN a.TABLE_TYPE = 'VIEW' THEN 'View'
ELSE 'Table'
END,
ISNULL(b.[name], 'NA'),
CASE WHEN b.indid = 0 THEN 'Table Row Data (table has no
clustered index)'
WHEN b.indid = 1 THEN 'Clustered Index (and table row data)'
WHEN b.indid = 255 THEN 'TEXT/NTEXT/IMAGE/XML Column Data'
ELSE 'Non Clustered Index'
END,
b.indid,
FILEGROUP_NAME(b.groupid),
b.groupid
FROM INFORMATION_SCHEMA.TABLES a WITH (NOLOCK)
INNER JOIN sysindexes b WITH (NOLOCK)
ON OBJECT_ID(a.TABLE_NAME) = b.[id]
WHERE INDEXPROPERTY(b.[id], b.[name], 'IsAutoStatistics') = 0
SET NOCOUNT OFF
SELECT *
FROM #tblFileGroupInfo WITH (NOLOCK)
ORDER BY TableOrViewName ASC, AttributeIndid ASC
-- Cleanup
IF OBJECT_ID('tempdb..#tblFileGroupInfo', 'U') IS NOT NULL
DROP TABLE #tblFileGroupInfo
GO
HTH,
AbbA
"rgn" wrote in message
> Is there a way to get a list of all the tables in a particular File Group.
>
> rgn >> Stay informed about: List of Tables in a FileGroup |
|
| Back to top |
|
 |  |
External

Since: Oct 08, 2010 Posts: 1
|
(Msg. 7) Posted: Fri Oct 08, 2010 3:54 pm
Post subject: List of Tables in a FileGroup [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
I use this query and it gives me not only tables but in which filegroup all the related indexes too.
select case when indexes.type_desc in ('HEAP','CLUSTERED')
then 'Table-' + indexes.type_desc
else ' NC Index' end as indexType,
rtrim(cast(
case when indexProperty(objects.object_id,indexes.name,'IsUnique') = 1
then 'unique ' else '' end +
case when isNull(objectProperty(object_id(schemas.name + '.'
+ indexes.name),'IsConstraint'),0) = 1
then 'constraint ' else '' end +
case when indexProperty(objects.object_id,indexes.name,'IsAutoStatistics') = 1
then 'auto ' else '' end +
case when indexProperty(objects.object_id,indexes.name,'IsStatistics') = 1
then 'statistics ' else '' end +
case when indexProperty(objects.object_id,indexes.name,'IsHypothetical') = 1
then 'hypothetical ' else '' end
as varchar(30))) as indexProperties,
schemas.name + '.' + objects.name as tableName,
coalesce(indexes.name,'') as indexName,
filegroups.name as filegroup
from sys.indexes as indexes
join sys.objects as objects
on indexes.object_id = objects.object_id
join sys.schemas as schemas
on objects.schema_id = schemas.schema_id
join sys.filegroups as filegroups
on indexes.data_space_id = filegroups.data_space_id
where objectproperty(indexes.object_id,'IsMSShipped') = 0
order by tableName, case when indexes.type_desc in ('HEAP','CLUSTERED') then 0 else 1 end
> On Monday, November 24, 2008 1:03 PM rg wrote:
> Is there a way to get a list of all the tables in a particular File Group.
>
> rgn
>> On Monday, November 24, 2008 1:59 PM Russell Fields wrote:
>> rgn,
>>
>> Almost, but not quite. What actually exists in filegroups are indexes. Of
>> course, index_id=1 is the clustered index or index_id=1 is the heap, either
>> of which include the leaf (data) pages. (Every index for a table could be
>> on a different filegroup.)
>>
>> So, here is a start:
>>
>> SELECT OBJECT_NAME(i.id) AS ObjectName,
>> i.name AS IndexName, ds.data_space_id, ds.type
>> FROM sys.indexes i
>> JOIN sys.data_spaces ds
>> ON i.data_space_id = ds.data_space_id
>>
>>
>> RLF
>>
>>
>> "rgn" wrote in message
>>
>>> On Monday, November 24, 2008 2:37 PM Kalen Delaney wrote:
>>> I guess we could play semantic games, but a heap is not an index, even
>>> though there is a row for it in sys.indexes.
>>> And, as I'm sure Russell knows (it was probably just his fingers that didn't
>>> know) the index_id for a heap is 0.
>>> A heap has no concept of leaf pages, it just has the data.
>>>
>>> The thing that I would have said 'almost but not quite' about, would be if
>>> the table is partitioned. Then the entire table may not be on a single
>>> filegroup. In the code below, data_space_id may not map to a filegroup, it
>>> may map to a partition scheme, which can be composed of hundred of different
>>> filegroups.
>>>
>>> --
>>> HTH
>>> Kalen Delaney, SQL Server MVP
>>> www.InsideSQLServer.com
>>> www.SQLTuners.com
>>>
>>>
>>> "Russell Fields" wrote in message
>>>
>>>> On Monday, November 24, 2008 2:53 PM Russell Fields wrote:
>>>> Kalen, Thanks both for correcting my mistyping and for expanding the
>>>> explanation. - RLF
>>>>> On Monday, November 24, 2008 4:45 PM Kalen Delaney wrote:
>>>>> it is just so rare that I find anything that needs correcting in your
>>>>> explanations ...
>>>>>
>>>>> --
>>>>> HTH
>>>>> Kalen Delaney, SQL Server MVP
>>>>> www.InsideSQLServer.com
>>>>> www.SQLTuners.com
>>>>>> On Monday, November 24, 2008 11:11 PM Abba wrote:
>>>>>> Hi Rgn,
>>>>>>
>>>>>> Here is a script that I got from Internet ...
>>>>>>
>>>>>> /*==================================================================================
>>>>>>
>>>>>> NAME: Get extended filegroup info for all DB tables and views
>>>>>> (location of data pages, indexes, etc)
>>>>>>
>>>>>> DESCRIPTION: This script returns the following extended filegroup
>>>>>> info
>>>>>> For all DB tables and indexed views:
>>>>>> 1. The table (or view) name
>>>>>> 2. The type of the object (i.e., table or view)
>>>>>> 3. The filegroup location of the clustered index (when
>>>>>> exists), non-clustered indexes, data pages (if other
>>>>>> than the clustered index), and the NTEXT/TEXT/IMAGE
>>>>>> column data.
>>>>>> 4. The indid (from sysindexes) that corresponds to
>>>>>> the attributes listed in (3).
>>>>>> 5. The filegroup name and id on which the items listed
>>>>>> in (3) are located.
>>>>>>
>>>>>> USER PARAMETERS: NA
>>>>>>
>>>>>> RESULTSET: TableOrViewName, [Table/View], AttributeName,
>>>>>> AttributeType,
>>>>>> AttributeIndid, FileGroupName, FileGroupID
>>>>>>
>>>>>> RESULTSET SORT: TableOrViewName, AttributeIndid
>>>>>>
>>>>>> USING TABLES/VIEWS: INFORMATION_SCHEMA.TABLES
>>>>>> sysindexes
>>>>>>
>>>>>> REVISIONS
>>>>>>
>>>>>> DATE DEVELOPER DESCRIPTION OF REVISION VERSION
>>>>>> ========= =============== =================================
>>>>>> ===========
>>>>>> 04/18/2005 Omri Bahat Initial release 1.00
>>>>>>
>>>>>> ==================================================================================
>>>>>> Copyright ?? SQL Farms Solutions, www.sqlfarms.com. All rights reserved.
>>>>>> This code may be used at no charge as long as this copyright notice is not
>>>>>> removed.
>>>>>> ==================================================================================*/
>>>>>>
>>>>>> -- Get all DB tables and views filegroup info
>>>>>>
>>>>>> SET NOCOUNT ON
>>>>>>
>>>>>> -- This table will hold the collected filegroup information
>>>>>> IF OBJECT_ID('tempdb..#tblFileGroupInfo', 'U') IS NOT NULL
>>>>>> DROP TABLE #tblFileGroupInfo
>>>>>>
>>>>>> CREATE TABLE #tblFileGroupInfo(
>>>>>> TableOrViewName NVARCHAR(128),
>>>>>> [Table/View] VARCHAR(16),
>>>>>> AttributeName NVARCHAR(128),
>>>>>> AttributeType VARCHAR(128),
>>>>>> AttributeIndid INT,
>>>>>> FileGroupName NVARCHAR(128),
>>>>>> FileGroupID INT)
>>>>>>
>>>>>>
>>>>>> -- Get the file group information for all indexes of all tables and indexed
>>>>>> views
>>>>>> -- on the database. Note that auto-statistics created by SQL server are
>>>>>> excluded,
>>>>>> -- since they are hardly of interest.
>>>>>> INSERT INTO #tblFileGroupInfo(
>>>>>> TableOrViewName,
>>>>>> [Table/View],
>>>>>> AttributeName,
>>>>>> AttributeType,
>>>>>> AttributeIndid,
>>>>>> FileGroupName,
>>>>>> FileGroupID)
>>>>>> SELECT a.TABLE_NAME,
>>>>>> CASE WHEN a.TABLE_TYPE = 'VIEW' THEN 'View'
>>>>>> ELSE 'Table'
>>>>>> END,
>>>>>> ISNULL(b.[name], 'NA'),
>>>>>> CASE WHEN b.indid = 0 THEN 'Table Row Data (table has no
>>>>>> clustered index)'
>>>>>> WHEN b.indid = 1 THEN 'Clustered Index (and table row data)'
>>>>>> WHEN b.indid = 255 THEN 'TEXT/NTEXT/IMAGE/XML Column Data'
>>>>>> ELSE 'Non Clustered Index'
>>>>>> END,
>>>>>> b.indid,
>>>>>> FILEGROUP_NAME(b.groupid),
>>>>>> b.groupid
>>>>>> FROM INFORMATION_SCHEMA.TABLES a WITH (NOLOCK)
>>>>>> INNER JOIN sysindexes b WITH (NOLOCK)
>>>>>> ON OBJECT_ID(a.TABLE_NAME) = b.[id]
>>>>>> WHERE INDEXPROPERTY(b.[id], b.[name], 'IsAutoStatistics') = 0
>>>>>>
>>>>>>
>>>>>> SET NOCOUNT OFF
>>>>>>
>>>>>> SELECT *
>>>>>> FROM #tblFileGroupInfo WITH (NOLOCK)
>>>>>> ORDER BY TableOrViewName ASC, AttributeIndid ASC
>>>>>>
>>>>>> -- Cleanup
>>>>>>
>>>>>> IF OBJECT_ID('tempdb..#tblFileGroupInfo', 'U') IS NOT NULL
>>>>>> DROP TABLE #tblFileGroupInfo
>>>>>> GO
>>>>>> HTH,
>>>>>> AbbA
>>>>>>
>>>>>>
>>>>>> "rgn" wrote in message
>>>>>>
>>>>>> Submitted via EggHeadCafe - Software Developer Portal of Choice
>>>>>> ComponentOne Studio for ASP.NET AJAX - Free License Giveaway
>>>>>> http://www.eggheadcafe.com/tutorials/aspnet/ce98ce1f-2b5d-4ec8-b6d5-a1...651514e >> Stay informed about: List of Tables in a FileGroup |
|
| Back to top |
|
 |  |
External

Since: Dec 03, 2010 Posts: 1
|
(Msg. 8) Posted: Fri Dec 03, 2010 8:56 am
Post subject: Re: I guess we could play semantic games, but a heap is not an index, [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Actually, from what I was told by a Microsoft engineer a heap is an index.
Supposedly it still has a clustered index. The index is just based on some random hashing algorithm. Basically all tables in SQL Server, heaps or otherwise, are what Oracle would call an Index Organized Table.
I have never verified this but that was what I was told.
> On Monday, November 24, 2008 1:03 PM rg wrote:
> Is there a way to get a list of all the tables in a particular File Group.
>
> rgn
>> On Monday, November 24, 2008 1:59 PM Russell Fields wrote:
>> rgn,
>>
>> Almost, but not quite. What actually exists in filegroups are indexes. Of
>> course, index_id=1 is the clustered index or index_id=1 is the heap, either
>> of which include the leaf (data) pages. (Every index for a table could be
>> on a different filegroup.)
>>
>> So, here is a start:
>>
>> SELECT OBJECT_NAME(i.id) AS ObjectName,
>> i.name AS IndexName, ds.data_space_id, ds.type
>> FROM sys.indexes i
>> JOIN sys.data_spaces ds
>> ON i.data_space_id = ds.data_space_id
>>
>>
>> RLF
>>
>>
>> "rgn" wrote in message
>>
>>> On Monday, November 24, 2008 2:37 PM Kalen Delaney wrote:
>>> I guess we could play semantic games, but a heap is not an index, even
>>> though there is a row for it in sys.indexes.
>>> And, as I'm sure Russell knows (it was probably just his fingers that didn't
>>> know) the index_id for a heap is 0.
>>> A heap has no concept of leaf pages, it just has the data.
>>>
>>> The thing that I would have said 'almost but not quite' about, would be if
>>> the table is partitioned. Then the entire table may not be on a single
>>> filegroup. In the code below, data_space_id may not map to a filegroup, it
>>> may map to a partition scheme, which can be composed of hundred of different
>>> filegroups.
>>>
>>> --
>>> HTH
>>> Kalen Delaney, SQL Server MVP
>>> www.InsideSQLServer.com
>>> www.SQLTuners.com
>>>
>>>
>>> "Russell Fields" wrote in message
>>>
>>>> On Monday, November 24, 2008 2:53 PM Russell Fields wrote:
>>>> Kalen, Thanks both for correcting my mistyping and for expanding the
>>>> explanation. - RLF
>>>>> On Monday, November 24, 2008 4:45 PM Kalen Delaney wrote:
>>>>> it is just so rare that I find anything that needs correcting in your
>>>>> explanations ...
>>>>>
>>>>> --
>>>>> HTH
>>>>> Kalen Delaney, SQL Server MVP
>>>>> www.InsideSQLServer.com
>>>>> www.SQLTuners.com
>>>>>> On Monday, November 24, 2008 11:11 PM Abba wrote:
>>>>>> Hi Rgn,
>>>>>>
>>>>>> Here is a script that I got from Internet ...
>>>>>>
>>>>>> /*==================================================================================
>>>>>>
>>>>>> NAME: Get extended filegroup info for all DB tables and views
>>>>>> (location of data pages, indexes, etc)
>>>>>>
>>>>>> DESCRIPTION: This script returns the following extended filegroup
>>>>>> info
>>>>>> For all DB tables and indexed views:
>>>>>> 1. The table (or view) name
>>>>>> 2. The type of the object (i.e., table or view)
>>>>>> 3. The filegroup location of the clustered index (when
>>>>>> exists), non-clustered indexes, data pages (if other
>>>>>> than the clustered index), and the NTEXT/TEXT/IMAGE
>>>>>> column data.
>>>>>> 4. The indid (from sysindexes) that corresponds to
>>>>>> the attributes listed in (3).
>>>>>> 5. The filegroup name and id on which the items listed
>>>>>> in (3) are located.
>>>>>>
>>>>>> USER PARAMETERS: NA
>>>>>>
>>>>>> RESULTSET: TableOrViewName, [Table/View], AttributeName,
>>>>>> AttributeType,
>>>>>> AttributeIndid, FileGroupName, FileGroupID
>>>>>>
>>>>>> RESULTSET SORT: TableOrViewName, AttributeIndid
>>>>>>
>>>>>> USING TABLES/VIEWS: INFORMATION_SCHEMA.TABLES
>>>>>> sysindexes
>>>>>>
>>>>>> REVISIONS
>>>>>>
>>>>>> DATE DEVELOPER DESCRIPTION OF REVISION VERSION
>>>>>> ========= =============== =================================
>>>>>> ===========
>>>>>> 04/18/2005 Omri Bahat Initial release 1.00
>>>>>>
>>>>>> ==================================================================================
>>>>>> Copyright ?? SQL Farms Solutions, www.sqlfarms.com. All rights reserved.
>>>>>> This code may be used at no charge as long as this copyright notice is not
>>>>>> removed.
>>>>>> ==================================================================================*/
>>>>>>
>>>>>> -- Get all DB tables and views filegroup info
>>>>>>
>>>>>> SET NOCOUNT ON
>>>>>>
>>>>>> -- This table will hold the collected filegroup information
>>>>>> IF OBJECT_ID('tempdb..#tblFileGroupInfo', 'U') IS NOT NULL
>>>>>> DROP TABLE #tblFileGroupInfo
>>>>>>
>>>>>> CREATE TABLE #tblFileGroupInfo(
>>>>>> TableOrViewName NVARCHAR(128),
>>>>>> [Table/View] VARCHAR(16),
>>>>>> AttributeName NVARCHAR(128),
>>>>>> AttributeType VARCHAR(128),
>>>>>> AttributeIndid INT,
>>>>>> FileGroupName NVARCHAR(128),
>>>>>> FileGroupID INT)
>>>>>>
>>>>>>
>>>>>> -- Get the file group information for all indexes of all tables and indexed
>>>>>> views
>>>>>> -- on the database. Note that auto-statistics created by SQL server are
>>>>>> excluded,
>>>>>> -- since they are hardly of interest.
>>>>>> INSERT INTO #tblFileGroupInfo(
>>>>>> TableOrViewName,
>>>>>> [Table/View],
>>>>>> AttributeName,
>>>>>> AttributeType,
>>>>>> AttributeIndid,
>>>>>> FileGroupName,
>>>>>> FileGroupID)
>>>>>> SELECT a.TABLE_NAME,
>>>>>> CASE WHEN a.TABLE_TYPE = 'VIEW' THEN 'View'
>>>>>> ELSE 'Table'
>>>>>> END,
>>>>>> ISNULL(b.[name], 'NA'),
>>>>>> CASE WHEN b.indid = 0 THEN 'Table Row Data (table has no
>>>>>> clustered index)'
>>>>>> WHEN b.indid = 1 THEN 'Clustered Index (and table row data)'
>>>>>> WHEN b.indid = 255 THEN 'TEXT/NTEXT/IMAGE/XML Column Data'
>>>>>> ELSE 'Non Clustered Index'
>>>>>> END,
>>>>>> b.indid,
>>>>>> FILEGROUP_NAME(b.groupid),
>>>>>> b.groupid
>>>>>> FROM INFORMATION_SCHEMA.TABLES a WITH (NOLOCK)
>>>>>> INNER JOIN sysindexes b WITH (NOLOCK)
>>>>>> ON OBJECT_ID(a.TABLE_NAME) = b.[id]
>>>>>> WHERE INDEXPROPERTY(b.[id], b.[name], 'IsAutoStatistics') = 0
>>>>>>
>>>>>>
>>>>>> SET NOCOUNT OFF
>>>>>>
>>>>>> SELECT *
>>>>>> FROM #tblFileGroupInfo WITH (NOLOCK)
>>>>>> ORDER BY TableOrViewName ASC, AttributeIndid ASC
>>>>>>
>>>>>> -- Cleanup
>>>>>>
>>>>>> IF OBJECT_ID('tempdb..#tblFileGroupInfo', 'U') IS NOT NULL
>>>>>> DROP TABLE #tblFileGroupInfo
>>>>>> GO
>>>>>> HTH,
>>>>>> AbbA
>>>>>>
>>>>>>
>>>>>> "rgn" wrote in message
>>>>>>
>>>>>>> On Friday, October 08, 2010 11:53 AM Sushil Patel wrote:
>>>>>>> I use this query and it gives me not only tables but in which filegroup all the related indexes too.
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> select case when indexes.type_desc in ('HEAP','CLUSTERED')
>>>>>>>
>>>>>>> then 'Table-' + indexes.type_desc
>>>>>>>
>>>>>>> else ' NC Index' end as indexType,
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> rtrim(cast(
>>>>>>>
>>>>>>> case when indexProperty(objects.object_id,indexes.name,'IsUnique') = 1
>>>>>>>
>>>>>>> then 'unique ' else '' end +
>>>>>>>
>>>>>>> case when isNull(objectProperty(object_id(schemas.name + '.'
>>>>>>>
>>>>>>> + indexes.name),'IsConstraint'),0) = 1
>>>>>>>
>>>>>>> then 'constraint ' else '' end +
>>>>>>>
>>>>>>> case when indexProperty(objects.object_id,indexes.name,'IsAutoStatistics') = 1
>>>>>>>
>>>>>>> then 'auto ' else '' end +
>>>>>>>
>>>>>>> case when indexProperty(objects.object_id,indexes.name,'IsStatistics') = 1
>>>>>>>
>>>>>>> then 'statistics ' else '' end +
>>>>>>>
>>>>>>> case when indexProperty(objects.object_id,indexes.name,'IsHypothetical') = 1
>>>>>>>
>>>>>>> then 'hypothetical ' else '' end
>>>>>>>
>>>>>>> as varchar(30))) as indexProperties,
>>>>>>>
>>>>>>> schemas.name + '.' + objects.name as tableName,
>>>>>>>
>>>>>>> coalesce(indexes.name,'') as indexName,
>>>>>>>
>>>>>>> filegroups.name as filegroup
>>>>>>>
>>>>>>> from sys.indexes as indexes
>>>>>>>
>>>>>>> join sys.objects as objects
>>>>>>>
>>>>>>> on indexes.object_id = objects.object_id
>>>>>>>
>>>>>>> join sys.schemas as schemas
>>>>>>>
>>>>>>> on objects.schema_id = schemas.schema_id
>>>>>>>
>>>>>>> join sys.filegroups as filegroups
>>>>>>>
>>>>>>> on indexes.data_space_id = filegroups.data_space_id
>>>>>>>
>>>>>>> where objectproperty(indexes.object_id,'IsMSShipped') = 0
>>>>>>>
>>>>>>> order by tableName, case when indexes.type_desc in ('HEAP','CLUSTERED') then 0 else 1 end
>>>>>>> Submitted via EggHeadCafe
>>>>>>> Microsoft ASP.NET For Beginners
>>>>>>> http://www.eggheadcafe.com/training-topic-area/ASP-NET/7/ASP.aspx >> Stay informed about: List of Tables in a FileGroup |
|
| Back to top |
|
 |  |
External

Since: May 30, 2004 Posts: 2061
|
(Msg. 9) Posted: Fri Dec 03, 2010 5:25 pm
Post subject: Re: I guess we could play semantic games, but a heap is not an index, even though [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
|
|
| Back to top |
|
 |  |
| Related Topics: | how to get a list of objects in a file or filegroup - hi all, To speed up the backup of a 23GB sql 2k db used for monthly archives I split the original file into 2 files in two separate file groups. I then moved all user tables and indexes on the secondary file group I defragged and shrunk the file but I...
Retrieve list of largest tables in a database - Hello, is there an easy way to retrieve a list of the largest tables in a given database? I know how to use stored procedures to retrieve the size of a single table, but I was wondering if there was a query that could be used to obtain a list of the 20....
Can't delete filegroup, even though it is empty - Hi All, I have a SQL 2000 database that I had created a seperate file group for to hold indexes. I have since deleted the indexes and want to delete the file groups. When I execute the ALTER DATABASE <dbname> REMOVE FILEGROUP <filegroupnam...
filegroup is offline after restore - I am using SQL-2005 Beta. I created 7 filegroups and associate them to a table "Myhour" through partition function and schema. It works fine. Then I tried the following statements to backup and retore the first filegroup: BACKUP DATABASE Mydb ...
Move only 1 filegroup to different server? - Is it possible to move only 1 partition/filegroup out of many from dev server to a production server? ie Everything except data in 1 partiton is the same and I would like to save time by just replacing the modified partiion. Thanks |
|
You can post new topics in this forum You can reply to topics in this forum You can edit your posts in this forum You can delete your posts in this forum You can vote in polls in this forum
|
|
|
|
 |
|
|