自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

判斷SQL數(shù)據(jù)庫中函數(shù)、存儲過程等是否存在的方法

數(shù)據(jù)庫 SQL Server
如果需要判斷SQL中的表、函數(shù)等是否存在,應(yīng)該怎么做呢?下面就為您介紹SQL判斷數(shù)據(jù)庫、表、存儲過程、視圖、函數(shù)是否存在的方法,供您參考。

下面為您介紹sql下用了判斷各種資源是否存在的代碼,需要的朋友可以參考下,希望對您學(xué)習(xí)sql的函數(shù)及數(shù)據(jù)庫能夠有所幫助。
庫是否存在
if exists(select * from master..sysdatabases where name=N'庫名')
print 'exists'
else
print 'not exists'
---------------
-- 判斷要創(chuàng)建的表名是否存在
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[表名]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
-- 刪除表
drop table [dbo].[表名]
GO
---------------
--判斷要創(chuàng)建臨時表是否存在
If Object_Id('Tempdb.dbo.#Test') Is Not Null
Begin
print '存在'
End
Else
Begin
print '不存在'
End
---------------
-- 判斷要創(chuàng)建的存儲過程名是否存在
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[存儲過程名]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
-- 刪除存儲過程
drop procedure [dbo].[存儲過程名]
GO
---------------
-- 判斷要創(chuàng)建的視圖名是否存在
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[視圖名]') and OBJECTPROPERTY(id, N'IsView') = 1)
-- 刪除視圖
drop view [dbo].[視圖名]
GO
---------------
-- 判斷要創(chuàng)建的函數(shù)名是否存在
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[函數(shù)名]') and xtype in (N'FN', N'IF', N'TF'))
-- 刪除函數(shù)
drop function [dbo].[函數(shù)名]
GO
if col_length('表名', '列名') is null
print '不存在'
select 1 from sysobjects where id in (select id from syscolumns where name='列名') and name='表名'

 

 

【編輯推薦】

SQL中CHARINDEX函數(shù)的調(diào)用方法

SQL中的分析函數(shù)

創(chuàng)建SQL函數(shù)的實例

SQL中返回計算表達式的函數(shù)

SQL中DATENAME函數(shù)的用法

責(zé)任編輯:段燃 來源: 互聯(lián)網(wǎng)
相關(guān)推薦

2011-05-30 14:30:08

函數(shù)存儲過程

2010-09-16 15:20:36

sql server表

2010-09-06 11:05:05

SQL SERVER語句

2010-09-10 15:11:07

SQLGetKey函數(shù)

2010-09-02 09:29:02

SQL刪除字段

2009-09-11 15:12:26

LINQ執(zhí)行存儲過程

2011-04-13 15:44:12

SQL Server數(shù)函數(shù)

2010-09-02 11:24:45

SQL刪除

2011-06-03 10:50:27

Java

2010-11-11 12:06:39

SQL自增列

2011-07-13 16:19:54

存儲過程SQL Server數(shù)

2011-09-01 14:00:11

SQL Server 存儲過程顯示表結(jié)構(gòu)

2010-09-09 14:31:31

SQL函數(shù)數(shù)據(jù)庫

2010-04-16 13:53:23

Oracle數(shù)據(jù)庫

2011-07-28 14:31:47

SQL Server數(shù)存儲過程

2011-07-19 15:18:46

存儲過程sql語句

2010-06-28 13:45:16

SQL Server

2011-08-29 10:55:03

SQL Server分頁存儲過程優(yōu)化效率分

2010-04-16 14:10:56

Oracle數(shù)據(jù)庫

2011-08-25 16:13:31

SQL Server批量替換數(shù)據(jù)
點贊
收藏

51CTO技術(shù)棧公眾號