国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

sqlserver 判斷庫、表、視圖等的存在

2019-11-08 20:27:02
字體:
供稿:網(wǎng)友

sql server 判斷是否存在數(shù)據(jù)庫,表,列,視圖

1 判斷數(shù)據(jù)庫是否存在 if exists (select * from sys.databases where name = ‘?dāng)?shù)據(jù)庫名’) drop database [數(shù)據(jù)庫名]

2 判斷表是否存在 if exists (select * from sysobjects where id = object_id(N’[表名]’) and OBJECTPROPERTY(id, N’IsUserTable’) = 1) drop table [表名]

3 判斷存儲過程是否存在 if exists (select * from sysobjects where id = object_id(N’[存儲過程名]’) and OBJECTPROPERTY(id, N’IsProcedure’) = 1) drop procedure [存儲過程名]

4 判斷臨時表是否存在 if object_id(‘tempdb..#臨時表名’) is not null drop table #臨時表名

5 判斷視圖是否存在

–判斷是否存在’MyView52’這個試圖 IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_NAME = N’MyView52’) PRINT ‘存在’ else PRINT ‘不存在’ 6 判斷函數(shù)是否存在 – 判斷要創(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’)) drop function [dbo].[函數(shù)名]

7 獲取用戶創(chuàng)建的對象信息

SELECT [name],[id],crdate FROM sysobjects where xtype=’U’

8 判斷列是否存在 if exists(select * from syscolumns where id=object_id(‘表名’) and name=’列名’) alter table 表名 drop column 列名

9 判斷列是否自增列 if columnproperty(object_id(‘table’),’col’,’IsIdentity’)=1 print ‘自增列’ else print ‘不是自增列’

SELECT * FROM sys.columns WHERE object_id=OBJECT_ID(‘表名’) AND is_identity=1

10 判斷表中是否存在索引

if exists(select * from sysindexes where id=object_id(‘表名’) and name=’索引名’) print ‘存在’ else print ‘不存在’

刪除索引 drop index 表名.索引名

或: drop index 索引名 on 表名(貌似2000不行)

11 查看數(shù)據(jù)庫中對象

SELECT * FROM sys.sysobjects WHERE name=’對象名’ SELECT * FROM sys.sysobjects WHERE name=’對象名’

from : http://www.cnblogs.com/JohnnyBao/p/3799054.html


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 晴隆县| 清丰县| 肥东县| 天门市| 晋江市| 海原县| 滦南县| 博野县| 盐城市| 镇康县| 深水埗区| 吉隆县| 沙坪坝区| 南安市| 库车县| 德惠市| 天祝| 方山县| 思南县| 南川市| 漯河市| 宕昌县| 托克托县| 峨边| 田林县| 油尖旺区| 长乐市| 兰西县| 南陵县| 芜湖县| 抚顺市| 谷城县| 高安市| 郓城县| 玛纳斯县| 长宁县| 丰县| 伊宁县| 临西县| 邳州市| 精河县|