How to check a table is created in db?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

In c#, Microsoft sql 2000, the name of db is "tc",and i want to check the
table "csharp" is exist or not . if it isnot exist, create it.!
======================================
SqlCommand cmd = new SqlCommand();
connection.open();
sSQL = "...." // how to write it.
cmd.CommandText = sSQL;
cmd.ExceutNonQuery();
.....
other statement
=============================
 
if not exists (select table_name from information_schema.tables where
table_name ='tc')
Create table tc (....)
 
Hi,

You can check if it does exist or not by querying sysobjects , those with
xtype = 'U' are tables

To create it you could send a CREATE table command.


Cheers,
 
Back
Top