Click to See Complete Forum and Search --> : SQL
Raptors Fan
June 19th, 2001, 05:15 PM
Hi,
Is there a way to check if a table exists using SQL? I need to check if a table exists so I can drop it. Currently, I take care of it by capturing the error it gives me when the table doesn't exist on the Access database when I try to drop it. However, I would prefer not to do this by responding to an error.
Thanks all,
RS
Tower
June 19th, 2001, 07:04 PM
No standard SQL expression for this. You can find this information in system table or use ADOX collection Tables
phunkydude
June 20th, 2001, 05:52 AM
To retrieve all the tables something like...
set cnn = new ADODB.Connection
cnn.Open DB_CONNECTION
set rstSchema = cnn.OpenSchema(adSchemaTables, Array(empty, empty, empty, "TABLE"))
Do Until rstSchema.EOF
rstSchema.MoveNext 'get nect table
Loop
HTH
Cimperiali
June 20th, 2001, 06:57 AM
You should be able to query (make a sql on) MSysObjects table. Is a system table where you can find the names of all existing objects in your access Db. Look for field "Name" and put condition where Name = your_serching_for_Table.
If you do not see the table in Access, go to menu "tools", "options" and in tabs "View" check "system objects"
Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.
Raptors Fan
June 21st, 2001, 03:40 PM
Thanks for your suggestions!
Jayson
June 21st, 2001, 06:29 PM
Here's a query you can run to check if a table exists on SQL Server, but I don't know if it will work for an Access Database.
if exists (select * from sysobjects where id = object_id('dbo.your_table_name') and sysstat = 99)
print 'it exists'
else
print 'doesn''t exist'
Thanks.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.