How to create the INDEX REBUILD statement on some specific tables in a DB??.

How to create the INDEX REBUILD statement on some specific tables in a DB.

SELECT ‘ALTER INDEX ‘+name+ ‘ ON ‘+DB_NAME()+’.dbo.’+OBJECT_NAME(id)
+’ REBUILD WITH (ONLINE=ON, MAXDOP=1, SORT_IN_TEMPDB=ON) ‘,
OBJECT_NAME(id) Tablename,name FROM sys.sysindexes
WHERE  OBJECT_NAME(id)  IN(  ‘table1’,
     ‘table2’,
     ‘table3’,
     ‘table4’)
AND name not like ‘_WA%’  /* Removing _WA_Sys_ like things. What is _WA_Sys_?? Please go through the info in this blog as follows*/
order by OBJECT_NAME(id), indid

_WA_Sys_ is nothing but automatically created statistics. Can we avoid _WA_Sys_. Yes _WA_Sys_ can be avoided by turning the auto stats off. Run following code to turn auto stats off.

ALTER DATABASE Tuitionaffordable SET AUTO_CREATE_STATISTICS OFF

INTERVIEW PREPARATION IN 30 MINs – Read Following wires for a quick interview preparation.

  1. SQL Server DBA “Interview Questions And Answers”
  2. SQL Azure Interview Questions and Answers Part – 1
  3. SQL Azure Interview Questions and Answers Part – 2
  4. Powershell Interview Questions and Answers

Regards,

Online MS SQL Classes @ http://tuitionaffordable.webstarts.com

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s