|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Monday, May 13, 2013 5:45 AM
Points: 462,
Visits: 643
|
|
| I know this comment is rather late in the day but I'm just revisiting your script - I've used it as the basis of something that suits what I want so thought I'd mention a simple performance improvement & that is to make the cursor a fast_forward cursor. Makes access to a "step through 1 row after another" type of cursor significantly faster.
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Monday, May 13, 2013 5:45 AM
Points: 462,
Visits: 643
|
|
Having used this as the basis for my own version though I best update again - there is an error in the code when you have multiple schemas in a database where tablenames are repeated (so schemaA.Table1 and schemaB.Table1).
Solution is to make the code schema aware, so changing this code section :
INSERT INTO #TEMPFRAG SELECT OBJECT_NAME(F.OBJECT_ID) OBJ,I.NAME IND, F.AVG_FRAGMENTATION_IN_PERCENT, F.PAGE_COUNT,TABLE_SCHEMA FROM SYS.DM_DB_INDEX_PHYSICAL_STATS (DB_ID(),NULL,NULL,NULL,NULL) F JOIN SYS.INDEXES I ON(F.OBJECT_ID=I.OBJECT_ID)AND I.INDEX_ID=F.INDEX_ID JOIN INFORMATION_SCHEMA.TABLES S ON (S.TABLE_NAME=OBJECT_NAME(F.OBJECT_ID)) --WHERE INDEX_ID<> 0 AND F.DATABASE_ID=DB_ID() AND OBJECTPROPERTY(I.OBJECT_ID,''ISSYSTEMTABLE'')=0'
with this
INSERT INTO #TEMPFRAG SELECT OBJECT_NAME(F.OBJECT_ID) , I.NAME IND , F.AVG_FRAGMENTATION_IN_PERCENT , F.PAGE_COUNT , s.name -- NOTE CHANGED FROM TABLE_SCHEMA --, i.allow_page_locks -- I use this to better handle allow_page_locks true / false FROM SYS.DM_DB_INDEX_PHYSICAL_STATS ('+cast(@DB_ID as varchar)+',NULL,NULL,NULL,NULL) F JOIN SYS.INDEXES I ON(F.OBJECT_ID=I.OBJECT_ID) AND I.INDEX_ID=F.INDEX_ID and i.is_disabled = 0 -- Note I'm skipping disabled indexes join sys.tables t on f.object_id = t.object_id -- NOTE NEW LINE TO REPLACE USE OF INFORMATION_SCHEMA join sys.schemas s on s.schema_id = t.schema_id -- NOTE NEW LINE TO COMPLETE JOIN --WHERE INDEX_ID<> 0 AND F.DATABASE_ID=DB_ID() AND OBJECTPROPERTY(I.OBJECT_ID,''ISSYSTEMTABLE'')=0
The only other change you want to make for the above to work is to add at the start of your code :
declare @DB_ID int set @DB_ID= DB_ID('Your DB Name Here')
Because that gets around a failure in the original source if you want to run this for any database from any database.
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Friday, December 21, 2012 5:24 AM
Points: 366,
Visits: 436
|
|
Thanks Mutthu...this goes to my briefcase.
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Tuesday, July 10, 2012 12:16 AM
Points: 6,
Visits: 59
|
|
HI Muthu ,
Good script given.
HI muthu, i have a Dought in Sqlserver2000 , IN sqlserver 2005 Copy_only option is there But In sql server2000 not there if hava log shiping or Replication iam using iam taken backup lsn chain will breakup.
In my production sqlserver2000 is there how to take a backup without lSN Breakup
Thank You Harishkumar.M
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Tuesday, July 10, 2012 12:16 AM
Points: 6,
Visits: 59
|
|
HI Muthu ,
Good script given.
HI muthu, i have a Dought in Sqlserver2000 , IN sqlserver 2005 Copy_only option is there But In sql server2000 not there if hava log shiping or Replication iam using iam taken backup lsn chain will breakup.
In my production sqlserver2000 is there how to take a backup without lSN Breakup
Thank You Harishkumar.M
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Monday, May 13, 2013 4:17 AM
Points: 1,123,
Visits: 4,422
|
|
macherla.harish (2/12/2010) HI Muthu ,
Good script given.
HI muthu, i have a Dought in Sqlserver2000 , IN sqlserver 2005 Copy_only option is there But In sql server2000 not there if hava log shiping or Replication iam using iam taken backup lsn chain will breakup.
In my production sqlserver2000 is there how to take a backup without lSN Breakup
Thank You Harishkumar.M
Please start a new thread
Muthukkumaran Kaliyamoorthy
Helping SQL DBAs and Developers >>>SqlserverBlogForum
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Monday, May 13, 2013 4:17 AM
Points: 1,123,
Visits: 4,422
|
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Monday, May 13, 2013 4:17 AM
Points: 1,123,
Visits: 4,422
|
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Friday, April 26, 2013 3:03 PM
Points: 3,
Visits: 203
|
|
I haven't read through the above replies to check, but has anyone received the below error ONLY when the SP is executed against a CS collated DB? e.g. "SQL_Latin1_General_CP1_CS_AS"
" Msg 208, Level 16, State 1, Line 2 Invalid object name 'SYS.DM_DB_INDEX_PHYSICAL_STATS'. "
It runs fine on any other DB. It might be the solution to my failed indexing scripts, won't know until I get it running for a little bit.
Thanks, Bobw
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Monday, May 13, 2013 4:17 AM
Points: 1,123,
Visits: 4,422
|
|
bobw1776 (11/30/2011) I haven't read through the above replies to check, but has anyone received the below error ONLY when the SP is executed against a CS collated DB? e.g. "SQL_Latin1_General_CP1_CS_AS"
" Msg 208, Level 16, State 1, Line 2 Invalid object name 'SYS.DM_DB_INDEX_PHYSICAL_STATS'. "
It runs fine on any other DB. It might be the solution to my failed indexing scripts, won't know until I get it running for a little bit.
Thanks, Bobw
Bobw,
Hi,
Ask a question in general forum ---> http://www.sqlservercentral.com/Forums/
you got 'Invalid object name' error the DMV available on 2005 onwards.
Muthukkumaran Kaliyamoorthy
Helping SQL DBAs and Developers >>>SqlserverBlogForum
|
|
|
|