<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: SQL SERVER &#8211; How to Enable Index &#8211; How to Disable Index &#8211; Incorrect syntax near &#8216;ENABLE&#8217;</title>
	<atom:link href="http://blog.sqlauthority.com/2009/10/27/sql-server-how-to-enable-index-how-to-disable-index-incorrect-syntax-near-enable/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sqlauthority.com/2009/10/27/sql-server-how-to-enable-index-how-to-disable-index-incorrect-syntax-near-enable/</link>
	<description>SQL, SQL Server, MySQL, Big Data and NoSQL</description>
	<lastBuildDate>Wed, 19 Jun 2013 20:36:26 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Vlad</title>
		<link>http://blog.sqlauthority.com/2009/10/27/sql-server-how-to-enable-index-how-to-disable-index-incorrect-syntax-near-enable/#comment-277017</link>
		<dc:creator><![CDATA[Vlad]]></dc:creator>
		<pubDate>Tue, 17 Apr 2012 17:43:30 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7121#comment-277017</guid>
		<description><![CDATA[Hello again,

Unfortunately, your idea to ‘ALTER INDEX ALL...’ will not work in my case   because disable all including clustered for Primary Key.
 I have created more specific store procedure. This one is using only developer created indexes started with &#039;IC_&#039;. Also I figure out one issue with it:  it has to be deployed in very db for it is working only for one database (you can not specify db name and use it as parameter). I could not fix it, however I left sys.tables inner join for future . In case if you have any idea to make more flexible, please, share this info.


  
--- !!!!!!!!   one stored procedure for every database !!!!!!!!!---------
 
IF  EXISTS (SELECT * FROM sys.objects 
WHERE object_id = OBJECT_ID(N&#039;[dbo].[Index__DISABLE_REBUILD]&#039;) 
AND type in (N&#039;P&#039;, N&#039;PC&#039;))
DROP PROCEDURE [dbo].[Index__DISABLE_REBUILD]
GO
create proc Index__DISABLE_REBUILD 
---- DISABLE/REBUILD  indexes in a db for any table based on parameters
--- e.g.
--   EXEC Index__DISABLE_REBUILD   &#039;Finance_Detail_Fact&#039;, &#039;DISABLE&#039; 
--   EXEC Index__DISABLE_REBUILD   &#039;Finance_Detail_Fact&#039;,&#039;REBUILD&#039;
--   EXEC Index__DISABLE_REBUILD   &#039;LOSSES&#039;, &#039;DISABLE&#039;
--   EXEC Index__DISABLE_REBUILD   &#039;LOSSES&#039;,&#039;REBUILD&#039;
  @table_name nvarchar(100), @status varchar(10) 
as
begin
	Declare c Cursor For select  distinct  
		&#039;ALTER INDEX [&#039;+ i.name  +&#039;] on &#039;+ t.name +&#039;  &#039;+ @status  
		from sys.tables t inner join 
		sys.schemas s on t.schema_id = s.schema_id 
		inner join sys.indexes i on i.object_id = t.object_id 
		inner join sys.index_columns ic on ic.object_id = t.object_id         
		inner join sys.columns c on c.object_id = t.object_id 
		and   ic.column_id = c.column_id    
		where      i.name   like &#039;IC_%&#039; 
		and			t.name = @table_name 
	Open c   
	FETCH NEXT FROM c INTO  @Table_name			 
		While @@Fetch_Status=0 Begin  
		  -- print @Table_name
			exec   ( @Table_name)
		   Fetch next From c into @Table_name
		End  
	Close c  
	Deallocate c 
end



Thanks,
Vlad]]></description>
		<content:encoded><![CDATA[<p>Hello again,</p>
<p>Unfortunately, your idea to ‘ALTER INDEX ALL&#8230;’ will not work in my case   because disable all including clustered for Primary Key.<br />
 I have created more specific store procedure. This one is using only developer created indexes started with &#8216;IC_&#8217;. Also I figure out one issue with it:  it has to be deployed in very db for it is working only for one database (you can not specify db name and use it as parameter). I could not fix it, however I left sys.tables inner join for future . In case if you have any idea to make more flexible, please, share this info.</p>
<p>&#8212; !!!!!!!!   one stored procedure for every database !!!!!!!!!&#8212;&#8212;&#8212;</p>
<p>IF  EXISTS (SELECT * FROM sys.objects<br />
WHERE object_id = OBJECT_ID(N&#8217;[dbo].[Index__DISABLE_REBUILD]&#8216;)<br />
AND type in (N&#8217;P', N&#8217;PC&#8217;))<br />
DROP PROCEDURE [dbo].[Index__DISABLE_REBUILD]<br />
GO<br />
create proc Index__DISABLE_REBUILD<br />
&#8212;- DISABLE/REBUILD  indexes in a db for any table based on parameters<br />
&#8212; e.g.<br />
&#8211;   EXEC Index__DISABLE_REBUILD   &#8216;Finance_Detail_Fact&#8217;, &#8216;DISABLE&#8217;<br />
&#8211;   EXEC Index__DISABLE_REBUILD   &#8216;Finance_Detail_Fact&#8217;,'REBUILD&#8217;<br />
&#8211;   EXEC Index__DISABLE_REBUILD   &#8216;LOSSES&#8217;, &#8216;DISABLE&#8217;<br />
&#8211;   EXEC Index__DISABLE_REBUILD   &#8216;LOSSES&#8217;,'REBUILD&#8217;<br />
  @table_name nvarchar(100), @status varchar(10)<br />
as<br />
begin<br />
	Declare c Cursor For select  distinct<br />
		&#8216;ALTER INDEX ['+ i.name  +'] on &#8216;+ t.name +&#8217;  &#8216;+ @status<br />
		from sys.tables t inner join<br />
		sys.schemas s on t.schema_id = s.schema_id<br />
		inner join sys.indexes i on i.object_id = t.object_id<br />
		inner join sys.index_columns ic on ic.object_id = t.object_id<br />
		inner join sys.columns c on c.object_id = t.object_id<br />
		and   ic.column_id = c.column_id<br />
		where      i.name   like &#8216;IC_%&#8217;<br />
		and			t.name = @table_name<br />
	Open c<br />
	FETCH NEXT FROM c INTO  @Table_name<br />
		While @@Fetch_Status=0 Begin<br />
		  &#8212; print @Table_name<br />
			exec   ( @Table_name)<br />
		   Fetch next From c into @Table_name<br />
		End<br />
	Close c<br />
	Deallocate c<br />
end</p>
<p>Thanks,<br />
Vlad</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vlad</title>
		<link>http://blog.sqlauthority.com/2009/10/27/sql-server-how-to-enable-index-how-to-disable-index-incorrect-syntax-near-enable/#comment-276653</link>
		<dc:creator><![CDATA[Vlad]]></dc:creator>
		<pubDate>Mon, 16 Apr 2012 13:23:56 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7121#comment-276653</guid>
		<description><![CDATA[Thanks a lot, Sepia. You save me life and carrier  :-)

Vlad.]]></description>
		<content:encoded><![CDATA[<p>Thanks a lot, Sepia. You save me life and carrier  :-)</p>
<p>Vlad.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sgupta10</title>
		<link>http://blog.sqlauthority.com/2009/10/27/sql-server-how-to-enable-index-how-to-disable-index-incorrect-syntax-near-enable/#comment-276292</link>
		<dc:creator><![CDATA[sgupta10]]></dc:creator>
		<pubDate>Sun, 15 Apr 2012 09:37:47 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7121#comment-276292</guid>
		<description><![CDATA[Hi Vlad,

Go through Pinal&#039;s article

http://blog.sqlauthority.com/2010/05/12/sql-server-understanding-alter-index-all-rebuild-with-disabled-clustered-index/

This would give you a basic knowledge of the commands. Now to put alter index command in a stored procedure, you can use code below:

create proc abc.myproc1
	@tabname nvarchar(100), @status varchar(10) 
as
begin
	declare @sqlbuff nvarchar(255)
	set @sqlbuff = &#039;Alter index all on abc.&#039; + @tabname + &#039; &#039; + @status
print @sqlbuff
	exec (@sqlbuff)
end
go

exec abc.myproc1 @tabname= test , @status = disable

This would display the command that will be executed by the stored procedure as well.

Cheers, Sepia]]></description>
		<content:encoded><![CDATA[<p>Hi Vlad,</p>
<p>Go through Pinal&#8217;s article</p>
<p><a href="http://blog.sqlauthority.com/2010/05/12/sql-server-understanding-alter-index-all-rebuild-with-disabled-clustered-index/" rel="nofollow">http://blog.sqlauthority.com/2010/05/12/sql-server-understanding-alter-index-all-rebuild-with-disabled-clustered-index/</a></p>
<p>This would give you a basic knowledge of the commands. Now to put alter index command in a stored procedure, you can use code below:</p>
<p>create proc abc.myproc1<br />
	@tabname nvarchar(100), @status varchar(10)<br />
as<br />
begin<br />
	declare @sqlbuff nvarchar(255)<br />
	set @sqlbuff = &#8216;Alter index all on abc.&#8217; + @tabname + &#8216; &#8216; + @status<br />
print @sqlbuff<br />
	exec (@sqlbuff)<br />
end<br />
go</p>
<p>exec abc.myproc1 @tabname= test , @status = disable</p>
<p>This would display the command that will be executed by the stored procedure as well.</p>
<p>Cheers, Sepia</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vlad</title>
		<link>http://blog.sqlauthority.com/2009/10/27/sql-server-how-to-enable-index-how-to-disable-index-incorrect-syntax-near-enable/#comment-275833</link>
		<dc:creator><![CDATA[Vlad]]></dc:creator>
		<pubDate>Fri, 13 Apr 2012 20:42:16 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7121#comment-275833</guid>
		<description><![CDATA[Hi,

I just wonder if you have any idea how to make it more flexible e.g. DISABLE / REBUILD all indexes in a table from stored procedure based on sys.tables and specified parameters like @table_name and @status -DISABLE / REBUILD

Thanks ahead,]]></description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>I just wonder if you have any idea how to make it more flexible e.g. DISABLE / REBUILD all indexes in a table from stored procedure based on sys.tables and specified parameters like @table_name and @status -DISABLE / REBUILD</p>
<p>Thanks ahead,</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Adam</title>
		<link>http://blog.sqlauthority.com/2009/10/27/sql-server-how-to-enable-index-how-to-disable-index-incorrect-syntax-near-enable/#comment-268481</link>
		<dc:creator><![CDATA[Adam]]></dc:creator>
		<pubDate>Tue, 27 Mar 2012 20:39:18 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7121#comment-268481</guid>
		<description><![CDATA[Good one!]]></description>
		<content:encoded><![CDATA[<p>Good one!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SQL SERVER – Interview Questions and Answers – Frequently Asked Questions – Day 13 of 31 Journey to SQLAuthority</title>
		<link>http://blog.sqlauthority.com/2009/10/27/sql-server-how-to-enable-index-how-to-disable-index-incorrect-syntax-near-enable/#comment-147834</link>
		<dc:creator><![CDATA[SQL SERVER – Interview Questions and Answers – Frequently Asked Questions – Day 13 of 31 Journey to SQLAuthority]]></dc:creator>
		<pubDate>Wed, 13 Jul 2011 01:30:46 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7121#comment-147834</guid>
		<description><![CDATA[[...] (Read more here) [...]]]></description>
		<content:encoded><![CDATA[<p>[...] (Read more here) [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SQL SERVER – Disable Clustered Index and Data Insert Journey to SQL Authority with Pinal Dave</title>
		<link>http://blog.sqlauthority.com/2009/10/27/sql-server-how-to-enable-index-how-to-disable-index-incorrect-syntax-near-enable/#comment-67657</link>
		<dc:creator><![CDATA[SQL SERVER – Disable Clustered Index and Data Insert Journey to SQL Authority with Pinal Dave]]></dc:creator>
		<pubDate>Thu, 29 Apr 2010 03:22:00 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7121#comment-67657</guid>
		<description><![CDATA[[...] Due to the same reason even reorganization of the index is not possible till the clustered index (which was disabled) is rebuild. Now let us come to the second part of the question, regarding receiving the error when clustered index is &#8216;enabled&#8217;. This is very common question I receive on the blog. (The following statement is written keeping the syntax of T-SQL in mind) Clustered indexes can be disabled but can not be enabled, they have to rebuild. It is intuitive to think that something which we have &#8216;disabled&#8217; can be &#8216;enabled&#8217; but the syntax for the same is &#8216;rebuild&#8217;. This issue has been explained here: SQL SERVER – How to Enable Index – How to Disable Index – Incorrect syntax near ‘ENABLE’. [...]]]></description>
		<content:encoded><![CDATA[<p>[...] Due to the same reason even reorganization of the index is not possible till the clustered index (which was disabled) is rebuild. Now let us come to the second part of the question, regarding receiving the error when clustered index is &#8216;enabled&#8217;. This is very common question I receive on the blog. (The following statement is written keeping the syntax of T-SQL in mind) Clustered indexes can be disabled but can not be enabled, they have to rebuild. It is intuitive to think that something which we have &#8216;disabled&#8217; can be &#8216;enabled&#8217; but the syntax for the same is &#8216;rebuild&#8217;. This issue has been explained here: SQL SERVER – How to Enable Index – How to Disable Index – Incorrect syntax near ‘ENABLE’. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian Tkatch</title>
		<link>http://blog.sqlauthority.com/2009/10/27/sql-server-how-to-enable-index-how-to-disable-index-incorrect-syntax-near-enable/#comment-57737</link>
		<dc:creator><![CDATA[Brian Tkatch]]></dc:creator>
		<pubDate>Thu, 19 Nov 2009 14:08:09 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7121#comment-57737</guid>
		<description><![CDATA[@Naresh

http://blog.sqlauthority.com/2009/06/23/sql-server-2005-2008-delete-duplicate-rows/

Pinal has a good deal of articles here. I found that one by searching for: delete duplicate records]]></description>
		<content:encoded><![CDATA[<p>@Naresh</p>
<p><a href="http://blog.sqlauthority.com/2009/06/23/sql-server-2005-2008-delete-duplicate-rows/" rel="nofollow">http://blog.sqlauthority.com/2009/06/23/sql-server-2005-2008-delete-duplicate-rows/</a></p>
<p>Pinal has a good deal of articles here. I found that one by searching for: delete duplicate records</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Naresh</title>
		<link>http://blog.sqlauthority.com/2009/10/27/sql-server-how-to-enable-index-how-to-disable-index-incorrect-syntax-near-enable/#comment-57728</link>
		<dc:creator><![CDATA[Naresh]]></dc:creator>
		<pubDate>Thu, 19 Nov 2009 07:06:49 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7121#comment-57728</guid>
		<description><![CDATA[Hi pinal,

Can u pls tell me how to delete duplicate records.

Thanks,
Naresh]]></description>
		<content:encoded><![CDATA[<p>Hi pinal,</p>
<p>Can u pls tell me how to delete duplicate records.</p>
<p>Thanks,<br />
Naresh</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: deep</title>
		<link>http://blog.sqlauthority.com/2009/10/27/sql-server-how-to-enable-index-how-to-disable-index-incorrect-syntax-near-enable/#comment-57095</link>
		<dc:creator><![CDATA[deep]]></dc:creator>
		<pubDate>Wed, 28 Oct 2009 07:33:55 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7121#comment-57095</guid>
		<description><![CDATA[Hi Pinal,

Once again a nice post.

@denny,


One step missed in earlier comment, find the correct steps mentioned below.

You can change the default path for the data and log file in the server properties.

Right click on the SQL instance –&gt; Properties --&gt;Database Settings.

In the Database setting page, under “Database Default Locations’, you can set your custom path for both data and log file.

Hope this will help.

Thanks.
Sudeepta.]]></description>
		<content:encoded><![CDATA[<p>Hi Pinal,</p>
<p>Once again a nice post.</p>
<p>@denny,</p>
<p>One step missed in earlier comment, find the correct steps mentioned below.</p>
<p>You can change the default path for the data and log file in the server properties.</p>
<p>Right click on the SQL instance –&gt; Properties &#8211;&gt;Database Settings.</p>
<p>In the Database setting page, under “Database Default Locations’, you can set your custom path for both data and log file.</p>
<p>Hope this will help.</p>
<p>Thanks.<br />
Sudeepta.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: deep</title>
		<link>http://blog.sqlauthority.com/2009/10/27/sql-server-how-to-enable-index-how-to-disable-index-incorrect-syntax-near-enable/#comment-57094</link>
		<dc:creator><![CDATA[deep]]></dc:creator>
		<pubDate>Wed, 28 Oct 2009 07:32:28 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7121#comment-57094</guid>
		<description><![CDATA[Hi Pinal,

Once again a nice post.

@denny,

You can change the default path for the data and log file in the server properties.

Right click on the SQL instance --&gt; Database Settings.

In the Database setting page, under &quot;Database Default Locations&#039;, you can set your custom path for both data and log file.

Hope this will help.

Thanks.
Sudeepta.]]></description>
		<content:encoded><![CDATA[<p>Hi Pinal,</p>
<p>Once again a nice post.</p>
<p>@denny,</p>
<p>You can change the default path for the data and log file in the server properties.</p>
<p>Right click on the SQL instance &#8211;&gt; Database Settings.</p>
<p>In the Database setting page, under &#8220;Database Default Locations&#8217;, you can set your custom path for both data and log file.</p>
<p>Hope this will help.</p>
<p>Thanks.<br />
Sudeepta.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: denny</title>
		<link>http://blog.sqlauthority.com/2009/10/27/sql-server-how-to-enable-index-how-to-disable-index-incorrect-syntax-near-enable/#comment-57080</link>
		<dc:creator><![CDATA[denny]]></dc:creator>
		<pubDate>Tue, 27 Oct 2009 15:27:55 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7121#comment-57080</guid>
		<description><![CDATA[gr8 post. very helpful indeed.

could you please spare a minute to answer my question below.
I hv sql 2008 installed. Whenever a new db is created, there is a path defaulted for the data and log files.
Is there any global setting available where this path can be changed, which would be reflected whenever a new db is created.

thx in advance.
Denny]]></description>
		<content:encoded><![CDATA[<p>gr8 post. very helpful indeed.</p>
<p>could you please spare a minute to answer my question below.<br />
I hv sql 2008 installed. Whenever a new db is created, there is a path defaulted for the data and log files.<br />
Is there any global setting available where this path can be changed, which would be reflected whenever a new db is created.</p>
<p>thx in advance.<br />
Denny</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Prashant</title>
		<link>http://blog.sqlauthority.com/2009/10/27/sql-server-how-to-enable-index-how-to-disable-index-incorrect-syntax-near-enable/#comment-57063</link>
		<dc:creator><![CDATA[Prashant]]></dc:creator>
		<pubDate>Tue, 27 Oct 2009 11:07:56 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/?p=7121#comment-57063</guid>
		<description><![CDATA[Hey! this is good one....really helped me...

Thanks]]></description>
		<content:encoded><![CDATA[<p>Hey! this is good one&#8230;.really helped me&#8230;</p>
<p>Thanks</p>
]]></content:encoded>
	</item>
</channel>
</rss>
