By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,028 Members | 1,108 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,028 IT Pros & Developers. It's quick & easy.

How to check a table is created in db?

P: n/a
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
=============================
Nov 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
if not exists (select table_name from information_schema.tables where
table_name ='tc')
Create table tc (....)
"zjut" <zj**@discussions.microsoft.com> skrev i en meddelelse
news:C2**********************************@microsof t.com...
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
=============================

Nov 16 '05 #2

P: n/a
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,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


"zjut" <zj**@discussions.microsoft.com> wrote in message
news:C2**********************************@microsof t.com...
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
=============================

Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.