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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to know if table is already in DB

Author  Topic 

raysefo
Constraint Violating Yak Guru

260 Posts

Posted - 2006-05-13 : 09:24:43
Hi,

i wanna know if a specific table is already in a db. How can i do it?
thanks

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-05-13 : 09:32:26
You can use INFORMATION_SCHEMA or sysobjects

select * from INFORMATION_SCHEMA.TABLES where TABLE_NAME = 'MyTable'


select * from sysobjects where xtype = 'U' and name = 'MyTabble'



KH

Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2006-05-14 : 03:21:33
Another way

if objectproperty(object_id('dbo.authors'),'IsUserTable') = 1
print 'table exists'
else
print 'table does not exist'



CODO ERGO SUM
Go to Top of Page
   

- Advertisement -