473,379 Members | 1,386 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

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....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

Dec 11 '06 #1
1 1104
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,'IndexI D') 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/m...S,SQL.90).aspx
--

Dec 11 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: felix_william | last post by:
Attention=3A Dear friend=2C REQUEST FOR BUSINESS RELATIONSHIP OF GREAT PROFITS I am HON=2E =28DR=2E=29 Felix William=2C the Director of Procurement and Contract Award at the Nigerian National...
0
by: felix_william | last post by:
Attention=3A Dear friend=2C REQUEST FOR BUSINESS RELATIONSHIP OF GREAT PROFITS I am HON=2E =28DR=2E=29 Felix William=2C the Director of Procurement and Contract Award at the Nigerian National...
1
by: SpiderSwamy | last post by:
Hi, I know little bit about asp, I am facing a problem in Validating the ASP Form.. Example: Stud ID: 501242016 FirstName: Ajit LastName: Kar
0
by: alok sengar | last post by:
hi, I have already tried this URL's code "http://www.java2s.com/Code/CSharp/Network/SimpleSNMP.htm" but I am getting error when i am creating a UDP type Socket and recieving packet from this...
1
by: sachinv1821 | last post by:
hi all , i am getting this Problem i am Unable to Load the DLL/ACM, the Problem with this (DLL /ACM ) is its a C code but this DLL using the C++ library i written a wrapper for C++ library and...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.