Showing posts with label Drop. Show all posts
Showing posts with label Drop. Show all posts

Monday, June 14, 2010

Check and drop existing view in SQL database

Check if view exists in SQL server database and drop it if required.

IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[TBL_View]') AND OBJECTPROPERTY(id, N'IsView') = 1)

BEGIN

DROP VIEW [dbo].[TBL_View]

END

Check and drop existing function in SQL database

Check if function exists in SQL server, and drop it if required.

IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[FN_Name]') AND xtype in (N'FN', N'IF', N'TF'))

BEGIN

DROP FUNCTION [dbo].[FN_Name]

END