Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Nowy
Yak Posting Veteran
57 Posts |
Posted - 2007-06-06 : 05:39:48
|
| How can I check whether an table exists?For example I try this, but doesn't workwhen exists Test then --do somethingelse -- do something else |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2007-06-06 : 05:42:32
|
| if exists (select * frmo sysobjects where name = 'mytable' and xtype = 'U')if object_id('mytable') is not nullif exists (select * from information_schema where table_name = 'mytable')You should never have to do this other than when releasing some updates.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
Nowy
Yak Posting Veteran
57 Posts |
Posted - 2007-06-06 : 05:45:26
|
| thnx |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-06-06 : 05:49:54
|
[code]if exists (select * from information_schema.tables where table_name = 'mytable')[/code] KH |
 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-06-06 : 05:59:00
|
| [code]If objectproperty(object_Id('mytable'), 'IsUserTable') IS NOT NULL print 'table exists'else print 'table does not exists'[/code]Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
Nowy
Yak Posting Veteran
57 Posts |
Posted - 2007-06-06 : 07:33:10
|
| what means objectproperty? |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
|
|
|
|
|