Friday, October 29, 2010

How to check SQL Table exists or not in SQL Server

CREATE PROCEDURE CheckIfTableExists(@TableName
)
AS NVARCHAR(100)AS
BEGIN
SET
DECLARE
NOCOUNT ON @TableId as VARCHAR(50)SELECT @TableId= OBJECT_ID(N'[dbo].' + @TableName + '')IF (@TableId IS NOT NULL)SELECT 'Table Exists'ELSESELECT 'Table do not exists'END

How to check:
EXEC CheckIfTableExists 'stores'

No comments:

Post a Comment