November 24, 2005 at 11:10 am
Hello all,
I am starting to write T-SQL script and can't find how to test if a table is present on a database.
Somebody could help me please ??
Thanks in adv
November 24, 2005 at 12:15 pm
Hi,
You can check using this qry:
USE yourDatabase
select * from sysobjects where name = 'yourTable'
Hello from Guatemala,
Ricardo
November 24, 2005 at 1:22 pm
If you are looking for tables you have to add xtype to the previous query:
select * from sysobjects where name = 'yourTable' and xtype = 'U'
Also, you can query the view information_schema.tables:
select * from information_schema.tables where table_name = 'yourTable'
November 25, 2005 at 6:04 am
YAW alternative (Yet Another Way)
-- If assumption is to check for existance first
IF OBJECT_ID('dbo.myTable') IS NOT NULL AND OBJECTPROPERTY(OBJECT_ID('dbo.myTable'), 'IsTable') = 1
-- If assumption is to check for non-existance first
IF OBJECT_ID('dbo.myTable') IS NULL
/Kenneth
November 25, 2005 at 7:32 am
It works very fine !! Thanks a lot
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply