Reply to Re: Urgent....please respond

Your name:

Reply:


Posted by David Portas on 12/11/06 07:19

frien wrote:
> I want to create a stored procedure to find if the index exists if not
> i have to create the index....i use following stored procedure....but
> does'nt seem to be working.......but when i hard code the query it does
> work... can u plz tell me were i am going wrong
>
> CREATE PROCEDURE [dbo].[sd_find_create_ind]
> @tblName varchar(255),
> @colName varchar(255),
> @indName varchar(255)
> AS
> declare @query varchar(1024)
> select @query = 'IF indexproperty(object_id('+@tblName+'),
> '+@indName+', ''IsClustered'') IS NULL
> CREATE INDEX '+@indName+' ON '+@tblName+'('+@colName+')'
> GO
>
> thanks a lot



IF INDEXPROPERTY(OBJECT_ID(@tblName),@indName,'IndexID') IS NULL
EXEC ('CREATE INDEX ['+@indName+'] ON ['+@tblName+']
(['+@colName+'])');


--
David Portas, SQL Server MVP

Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.

SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация