Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Does a table exist? 1

Status
Not open for further replies.

innmedia

Programmer
Mar 24, 2000
108
US
Hi all,

Just wondering the best way to tell if a table exists before writing data to it. This would be from an Access front end. Is there a particular stored proc? Or is it a query into one of the system tables?

Thanks!

KB
 
You could write a SP that returned the count of the number of table objects that matched the table name in question.
Code:
Select Count(Id) From sysObjects 
   WHERE Name='YourTableName' and xType='U'
I believe the 'U' restricts the count to tables rather than SPs or views, etc. BTW, this is not how you would write the SP. Ask if you need help.
-Karl

[red] Cursors, triggers, user-defined functions and dynamic SQL are an axis of evil![/red]
[green]Life's uncertain...eat dessert first...www.deerfieldbakery.com[/green]
 
Donutman -

Perfect! Thanks, it's just what I needed.
 
Use the Information_Schema views to return information on database objects. They are visible in the master database, but exist in every database.
Code:
IF EXISTS(SELECT * FROM Information_Schema.Tables
          WHERE Table_Name = 'SomeTable')
   DROP TABLE SomeTable

--John [rainbow]
-----------------------------------
Behold! As a wild ass in the desert
go forth I to do my work.
--Gurnie Hallock (Dune)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top