Check availability of a table
i m creating a table using this query
Select * into newtable from oldtable
This is query wen u want to create an empty newtable with a structure of old table
now , uptill this it works fine , but now i want to check if newtable already exists so i wrote
if not exists ( Select * into newtable from oldtable)
it gives syntax error why?
Posted Jun 20, 2007, 12:37 AM
PHANI NADIGADDAPosted Feb 26, 2007, 1:47 PM
Strange
, this is how I tried and it worked successfully the way I wanted.IF OBJECT_ID('USERS1', 'U') IS NULL
SELECT * INTO USERS1 FROM USERS
I expected it should not give any error because there is no fault in this to get an error and I do not have an idea about this type of error.
I recommend to try again and I am sure you will get it with out any errors.
ALL THE BEST.
sheetu sachdevaPosted Feb 21, 2007, 11:17 PM
PHANI NADIGADDAPosted Feb 21, 2007, 4:17 PM
SELECT * FROM sysObject order by xtype
ALL THE BEST
sheetu sachdevaPosted Feb 20, 2007, 11:29 PM
PHANI NADIGADDAPosted Feb 20, 2007, 6:42 PM
You can try this way too
OBJECT_ID('TABLE_NAME','U') IS NOT NULLIF
PRINT 'Available'
ELSE
PRINT 'Unavailable'
ALL THE BEST