Check for index before creation in DBAccess
Posted in 1999
Topics: Stored Procedures & SPL, Server Administration
Hi all,
Does anyone know if it is possible to check for an index existence before
attempting to actually create the index. Similar to the following:
if not exists (select * from sysindexes where idxname = 'onekidx1')
create index onekidx1 on onektup ( unique1 );
I would like to accomplish this without using a stored procedure.
TIA,
John E. Porcello, Jr.
Corporate DBA
Kaman Corporation
jep-corp@kaman.com
My views and opinions may not reflect those of Kaman Corporation.
"Porcello, John" wrote:
> Does anyone know if it is possible to check for an index existence
> before attempting to actually create the index. Similar to the
> following:
>
> if not exists (select * from sysindexes where idxname = 'onekidx1')
> create index onekidx1 on onektup ( unique1 );>
> I would like to accomplish this without using a stored procedure.
John,
what you want to do is not possible under SQL directly. Under Jonathan's
sqlcmd program, maybe. But I would use a shell script:
dbaccess - - <<%%
create index onekidx1 on onektup ( unique1 );%%
If the index does not exist yet, it will get created. If an index by
that name already does exist, it will fail of course. I recall that in
an sql script file, you can put shell commands in lines that start
with a ! . So if you are doing a lot of stuff in an SQL script, you can
invoke the above shell script by referencing it in a !line. Either way
your SQL script continues on its merry way, even if the create index
failed.
--
-- Jake (Capable of distinguishing his gluteus maximus
from his proximal radioulnar articulation)
+------------------------------------------------------------+
| I am inhibited by the presence of a lady. I therefore can- |
| not properly express my opinion of your ancestry, personal |
| habits, morals or destination. |
| -- Robert A. Heinlein |
+------------------------------------------------------------+