SqlServer存在并删除 表,函数,view等

--表

if exists (select * from dbo.sysobjects where id = object_id(N'[monthly_budget_work]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [monthly_budget_work]
GO

--函数

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[fn_all_date_in_term]') and xtype in (N'FN', N'IF', N'TF'))
drop function [dbo].[fn_all_date_in_term]
GO

--View

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[view_loss]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[view_loss]
GO

--Trigger

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[InsertTrigger_postrn]') and OBJECTPROPERTY(id, N'IsTrigger') = 1)
drop trigger [dbo].[InsertTrigger_postrn]
GO

--SP

IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_download_sales_for_hojinkan]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[sp_download_sales_for_hojinkan]
GO

--synonyms

IF EXISTS (SELECT * FROM sys.synonyms WHERE name = N'FEP_kbn_manage')
DROP SYNONYM [dbo].[FEP_kbn_manage]
GO

--assemblies

IF EXISTS (SELECT * FROM sys.assemblies asms WHERE asms.name = N'SqlServerDebug')
DROP ASSEMBLY [SqlServerDebug]
GO

--FK

if exists(select *  from sysobjects where name='fk_foreignkey1' and xtype='F')
ALTER TABLE dbo.table1 DROP CONSTRAINT fk_foreignkey1
GO

 

posted @ 2015-06-18 22:45  普贤  阅读(1863)  评论(0编辑  收藏  举报