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?

PHANI NADIGADDA51 reputationPosted Feb 20, 2007, 1:42 PM EST
You can try this way too
OBJECT_ID('TABLE_NAME','U') IS NOT NULLIF
PRINT 'Available'
ELSE
PRINT 'Unavailable'
ALL THE BEST
sheetu sachdeva33 reputationPosted Feb 20, 2007, 6:29 PM EST
PHANI NADIGADDA51 reputationPosted Feb 21, 2007, 11:17 AM EST
SELECT * FROM sysObject order by xtype
ALL THE BEST
sheetu sachdeva33 reputationPosted Feb 21, 2007, 6:17 PM EST
PHANI NADIGADDA51 reputationPosted Feb 26, 2007, 8:47 AM EST
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.
Posted Jun 19, 2007, 8:37 PM EDT