how to know the table is exist in the database

  • Thread starter Thread starter joy.net
  • Start date Start date
Depends on the database and/or on the database access method...

E.g. if you want to know if the Orders table exists in SQL Server, send it
the following scalar query:

SELECT COUNT(*) FROM sysobjects WHERE name = 'Orders'

If the result is 1, the table exists - if the result is 0, the table doesn't
exist.
 
Hi Mark,

Actually, executing sp_tables stored procedure is better since sysobjects
structure or accesibility might change at some point.
 
As Mark suggested - it depends on the database and provider used.
You might use OleDbConnection.GetOleDbSchemaTable method for example, or a
database specific method or query.
 
Actually, executing sp_tables stored procedure is better since sysobjects
structure or accesibility might change at some point.

LOL! As might the sp_tables stored procedure... :-)
 
Mark Rae said:
LOL! As might the sp_tables stored procedure... :-)

No, AFAIK it isn't recommended accessing sysobjects directly because it
might really change while stored procedures such as sp_tables will still
accept same parameters and will yield same output.
 
No, AFAIK it isn't recommended accessing sysobjects directly because it
might really change while stored procedures such as sp_tables will still
accept same parameters and will yield same output.

So none of the system stored procedures has ever changed...?
 
Mark Rae said:
So none of the system stored procedures has ever changed...?
My Teacher tell us don't use the stored procedures in my csharp code . so
that i must write code to make sure the table is exist or not.
 
My Teacher tell us don't use the stored procedures in my csharp code . so
that i must write code to make sure the table is exist or not.

In that case, you should consider finding another teacher...
 
Back
Top