ISSUE :
 
Profile photo
Submitted by Philip Harley
on October 12th, 2011 at 08:53:08 EST

SQL Server - How to check if table or stored procedure already exists?

Is there any way to check if table or stored procedure already exists? I am writing SQL script where I have to check if table or stored procedure exists before creating a new one.
Any help will be highly appreciated.


Profile photo
on October 18th, 2011 at 13:30:18 EST
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Pr_GetAllActiveRequest]') AND type in (N'P', N'PC'))
................

Profile photo
Replied by Sam Buchana
on November 1st, 2011 at 11:29:04 EST
Try this

IF OBJECT_ID('[dbo].[StoredProcName]') IS NOT NULL
BEGIN
/*Drop the table*/
DROP PROCEDURE [dbo].[StoredProcName]
END
Accepted Answer
Accepted
 Answer