Here are some useful
SQL Server commands that I have been asked several times in the past
How to find if a table exists in a database open a recordset with the following sql statement:
Code:
SELECT name FROM sysobjects WHERE xtype = 'U' AND name = 'MyTable'
If the recordset it at eof then the table doesn't exist if it has a record then the table does exist.
To get a list of databases on a server execute the following: Code:
SELECT * FROM master..sysdatabases
To leave out the standard system databases: Code:
SELECT * FROM master..sysdatabases WHERE name NOT IN ('tempbd', 'master', 'model', 'msdb')
To see if a database table has a column: Code:
SELECT * FROM dbo.syscolumns WHERE id = object_id(N'[dbo].[TableName]') AND name = 'FieldName'
To see if a stored procedure exists: Code:
SELECT * FROM sysobjects WHERE xtype = 'P' AND name = 'storedprocedurename'
John Spano
President
NeoTekSystems, Inc.
www.NeoTekSystems.com
Microsoft MVP, MCSD, MCTS-Windows, MCTS-Web, MCPD-Distributed, MCITP-SQLDev, MCITP-SQLAdmin