Urgent....please respond

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • frien

    Urgent....please respond

    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....bu t
    does'nt seem to be working.......b ut 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(o bject_id('+@tbl Name+'),
    '+@indName+', ''IsClustered'' ) IS NULL
    CREATE INDEX '+@indName+' ON '+@tblName+'('+ @colName+')'
    GO

    thanks a lot

  • David Portas

    #2
    Re: Urgent....pleas e respond

    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....bu t
    does'nt seem to be working.......b ut 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(o bject_id('+@tbl Name+'),
    '+@indName+', ''IsClustered'' ) IS NULL
    CREATE INDEX '+@indName+' ON '+@tblName+'('+ @colName+')'
    GO
    >
    thanks a lot


    IF INDEXPROPERTY(O BJECT_ID(@tblNa me),@indName,'I ndexID') 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:

    --

    Comment

    Working...