January 7, 2014 at 10:45 am
I need to increase fragmentation level for an index. This is in production, and the table has a lot of FK relations, so I can't do things like insert/delete. The reason for this is I am debugging my script but the index that I am aiming for has low level of frag.
Thanks
January 7, 2014 at 11:43 am
SQL Guy 1 (1/7/2014)
I need to increase fragmentation level for an index. This is in production, and the table has a lot of FK relations, so I can't do things like insert/delete. The reason for this is I am debugging my script but the index that I am aiming for has low level of frag.Thanks
Why are trying to debug your script in production???
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
January 7, 2014 at 11:56 am
This server is used by 3rd party applications and not frequently used. I want to debug some rare case in my defragmentation script, it happens only in a adatabase that's on this server, and it's not backed up.
January 8, 2014 at 2:05 am
You can't really fragment an index with modifying the data. Don't test stuff in production.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
January 8, 2014 at 9:18 am
OK, let's assume that I am not in production. How can I increase fragmentation without modifying the data?
January 8, 2014 at 9:25 am
SQL Guy 1 (1/8/2014)
OK, let's assume that I am not in production. How can I increase fragmentation without modifying the data?
You can't.
fragmentation occurs, for example, when data is inserted into the middle of an index, and when rows get added or deleted.
you could create a new sample table, insert and delete data randomly into that table from the source, and then look at the fragmentation of that test tables indexes both before and after.
Lowell
January 8, 2014 at 10:33 am
run a dbcc shrinkfile on it, you'll have all the fragmentation you want.
but not in production 🙂
---------------------------------------------------------------------
January 8, 2014 at 10:42 am
SQL Guy 1 (1/7/2014)
This server is used by 3rd party applications and not frequently used. I want to debug some rare case in my defragmentation script, it happens only in a adatabase that's on this server, and it's not backed up.
if you have any control over this, get it backed up even if its only used infrequently
---------------------------------------------------------------------
January 8, 2014 at 11:10 am
Yes, it's always backed up periodically.
DBCC shrink file did not help. First, it shrinks entire file which also has other tables. And it shrank just little bit because there was not much empty space was there.
Will alter table with increasing size of varchar columns work?
January 8, 2014 at 11:14 am
george sibbald (1/8/2014)
run a dbcc shrinkfile on it, you'll have all the fragmentation you want.
+1
but not in production 🙂
+1000!!!
--Jeff Moden
Change is inevitable... Change for the better is not.
January 8, 2014 at 11:20 am
SQL Guy 1 (1/8/2014)
Yes, it's always backed up periodically.DBCC shrink file did not help. First, it shrinks entire file which also has other tables. And it shrank just little bit because there was not much empty space was there.
Will alter table with increasing size of varchar columns work?
Run a select from sys.dm_db_index_physical_stats in the 'Detailed' mode and see just how badly things got fragmented.
But, I agree... DBCC Shrink File won't help here because it fragments EVERYTHING in the given file.
Increasing the Size of varchar columns (assuming you mean the width of the column and not the data itself) won't do it.
To reiterate what others have stated, you really must not do this in prod. Make a copy of the table in a Dev box, instead. As careful as you think you are, doing this in prod is just inviting disaster. Been there and done that. Not going to do it again. 🙂
--Jeff Moden
Change is inevitable... Change for the better is not.
January 8, 2014 at 11:39 am
why does it matter that other tables are fragmented? what is your script trying to do?
can you force the logic flow to pick up your table?
---------------------------------------------------------------------
January 8, 2014 at 11:42 am
george sibbald (1/8/2014)
why does it matter that other tables are fragmented? what is your script trying to do?can you force the logic flow to pick up your table?
agreed; what difference does it make WHICH table's indexes you defragment, if you are testing code? if you need to see the amount of time it takes to run, and an estimate won't do, then find the same data on your test server (you have one, right?) and run it there.
Lowell
January 9, 2014 at 9:50 am
Yes, I have in my code: where t.name = <my_table_name>.
But the level of fragmentation is so low, that my script skips it. And this is exactly the reason why I wanted to increase fragmentation somehow.
Viewing 14 posts - 1 through 14 (of 14 total)
You must be logged in to reply to this topic. Login to reply