SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


REBUILD THE INDEXES BY FILE GROUP


REBUILD THE INDEXES BY FILE GROUP

Author
Message
hydbadrose
hydbadrose
SSC-Addicted
SSC-Addicted (452 reputation)SSC-Addicted (452 reputation)SSC-Addicted (452 reputation)SSC-Addicted (452 reputation)SSC-Addicted (452 reputation)SSC-Addicted (452 reputation)SSC-Addicted (452 reputation)SSC-Addicted (452 reputation)

Group: General Forum Members
Points: 452 Visits: 934
gURU'S, Can someone please tell me how to defrag or rebuild the indexes by filegroup. I have about 37 filegroups by month and I want to rebuild only the current month indexes. Please HELP!
Florian Reischl
Florian Reischl
SSCarpal Tunnel
SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)

Group: General Forum Members
Points: 4731 Visits: 3934
Hi

Do you mean something like this?


SELECT st.name table_name,
si.name index_name,
sd.name data_space_name,
'DBCC DBREINDEX("' + SCHEMA_NAME(st.schema_id) + '.' + st.name + '", ' + QUOTENAME(si.name) + ')'
FROM sys.indexes si
JOIN sys.tables st ON si.object_id = st.object_id
JOIN sys.data_spaces sd ON si.data_space_id = sd.data_space_id
WHERE sd.name = 'ATTACHMENTS'



37 file groups per month? I always thought file groups are master data... :-D.

Greets
Flo


The more I learn, the more I know what I do not know
Blog: Things about Software Architecture, .NET development and T-SQL

How to Post Data/Code to get the best Help How to Post Performance Problems
hydbadrose
hydbadrose
SSC-Addicted
SSC-Addicted (452 reputation)SSC-Addicted (452 reputation)SSC-Addicted (452 reputation)SSC-Addicted (452 reputation)SSC-Addicted (452 reputation)SSC-Addicted (452 reputation)SSC-Addicted (452 reputation)SSC-Addicted (452 reputation)

Group: General Forum Members
Points: 452 Visits: 934
Thanks for the script, but it did not point to the current month. How do you only run on current month?
Florian Reischl
Florian Reischl
SSCarpal Tunnel
SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)

Group: General Forum Members
Points: 4731 Visits: 3934
How to identify the current month? By index creation date? Is it part of the file group name?


The more I learn, the more I know what I do not know
Blog: Things about Software Architecture, .NET development and T-SQL

How to Post Data/Code to get the best Help How to Post Performance Problems
hydbadrose
hydbadrose
SSC-Addicted
SSC-Addicted (452 reputation)SSC-Addicted (452 reputation)SSC-Addicted (452 reputation)SSC-Addicted (452 reputation)SSC-Addicted (452 reputation)SSC-Addicted (452 reputation)SSC-Addicted (452 reputation)SSC-Addicted (452 reputation)

Group: General Forum Members
Points: 452 Visits: 934
Part of the filegroup name.
Florian Reischl
Florian Reischl
SSCarpal Tunnel
SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)

Group: General Forum Members
Points: 4731 Visits: 3934
Hi

An example for the names would be grate ;-)

Well, assumed the file group name would be "FILE_GROUP_YYYY_M" where "YYYY" identifies the year and "M" identifies the month.


DECLARE @date datetime
SET @date = GETDATE()
DECLARE @fg_name NVARCHAR(128)

SET @fg_name = 'FILE_GROUP_' + CONVERT(VARCHAR(4), DATEPART(YEAR, @date)) + '_' + CONVERT(VARCHAR(2), DATEPART(MONTH, @date))


SELECT st.name table_name,
si.name index_name,
sd.name data_space_name,
'DBCC DBREINDEX("' + SCHEMA_NAME(st.schema_id) + '.' + st.name + '", ' + QUOTENAME(si.name) + ')'
FROM sys.indexes si
JOIN sys.tables st ON si.object_id = st.object_id
JOIN sys.data_spaces sd ON si.data_space_id = sd.data_space_id
WHERE sd.name = @fg_name



Greets
Flo


The more I learn, the more I know what I do not know
Blog: Things about Software Architecture, .NET development and T-SQL

How to Post Data/Code to get the best Help How to Post Performance Problems
hydbadrose
hydbadrose
SSC-Addicted
SSC-Addicted (452 reputation)SSC-Addicted (452 reputation)SSC-Addicted (452 reputation)SSC-Addicted (452 reputation)SSC-Addicted (452 reputation)SSC-Addicted (452 reputation)SSC-Addicted (452 reputation)SSC-Addicted (452 reputation)

Group: General Forum Members
Points: 452 Visits: 934
Thanks a bunch! I will try this and let you know how it works-
Florian Reischl
Florian Reischl
SSCarpal Tunnel
SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)

Group: General Forum Members
Points: 4731 Visits: 3934
Glad to help you! :-)


The more I learn, the more I know what I do not know
Blog: Things about Software Architecture, .NET development and T-SQL

How to Post Data/Code to get the best Help How to Post Performance Problems
hydbadrose
hydbadrose
SSC-Addicted
SSC-Addicted (452 reputation)SSC-Addicted (452 reputation)SSC-Addicted (452 reputation)SSC-Addicted (452 reputation)SSC-Addicted (452 reputation)SSC-Addicted (452 reputation)SSC-Addicted (452 reputation)SSC-Addicted (452 reputation)

Group: General Forum Members
Points: 452 Visits: 934
I forgot to ask about the statistics- How should I update the current month filegroup ' FG_MSG' statistics? Do you have the script for that as well? Thanks
Lowell
Lowell
SSC-Dedicated
SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)

Group: General Forum Members
Points: 35958 Visits: 40253
the same script that Florian gave you, simply change the file group name and change the line that says DBCC REINDEX to this:

'UPDATE STATISTICS ' + SCHEMA_NAME(st.schema_id) + '.' + st.name



Lowell

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search