Sql Server中判断表或者数据库是否存在
来源:互联网 发布:极限矩阵 核弹nuke x 编辑:程序博客网 时间:2024/05/01 23:20
SQL Server中判断数据库是否存在:
select * From master.dbo.sysdatabases where name='pubs'
最初安装 SQL Server 时,sysdatabases 包含 master、model、msdb、mssqlweb 和 tempdb 数据库的项。该表只存储在 master 数据库中。
但在实际使用中,需判断Status状态位:
其中某些状态位可由用户使用 sp_dboption(read only、dbo use only、single user 等)进行设置:
1 = autoclose;使用 sp_dboption 设置。 数据库完全关闭,其资源在最后一个用户注销后释放。
4 = select into/bulkcopy;使用 sp_dboption 设置。允许使用 Select INTO 语句和快速大容量复制。
8 = trunc. log on chkpt;使用 sp_dboption 设置。如果数据库处于日志截断模式,则检查点将截断日志中非活动的部分。只能为 master 数据库设置此选项。16 = torn page detection,使用 sp_dboption 设置。可以检测残缺页。
32 = loading。
64 = pre recovery。
128 = recovering。
256 = not recovered。
512 = offline;使用sp_dboption 设置。数据库将处于脱机状态。
1024 = read only;使用 sp_dboption 设置。用户仅能读取数据库中的数据而无法对其进行修改。
2048 = dbo use only;使用sp_dboption 设置。只有数据库所有者可以使用数据库。
4096 = single user;使用 sp_dboption 设置。每次只能有一个用户访问数据库。
32768 = emergency mode。
4194304 = autoshrink。
1073741824 = cleanly shutdown。
可以同时打开多个位。
譬如:判断一个数据库是否offline
select * From master.dbo.sysdatabases where name='pubs' and status<>512
SQL Server中判断表对象是否存在:
select count(*) from sysobjects where id = object_id('数据库名.Owner.表名')
if exists
(select count(*) from sysobjects where id = object_id('数据库名.Owner.表名'))
print '存在'
else
print '不存在'
SQL Server中判断表中字段是否存在:
if exists(select * from syscolumns where name='colname1' and id=object_id('数据库名.Owner.表名'))
print '存在'
else
print '不存在'
代表表tablename1中存在colname1字段
例:
select * from syscolumns where name='Test' and id=object_id('dbo.test')
Access中判断表对象是否存在:
其实,Access数据库也有系统表,存放有对象名
Select Count(*) AS Qty FROM MSysObjects Where ((MSysObjects.Name) Like '表名');
判断数据库和表是否存在
if not exists(select 1 From master.dbo.sysdatabases where name=N'JZKStarCfg')
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/thankyourfish/archive/2008/01/10/2034368.aspx
- Sql Server中判断表或者数据库是否存在
- Sql Server中判断表或者数据库是否存在
- Sql Server中判断表或者数据库是否存在
- Sql Server中判断表或者数据库是否存在
- Sql Server中判断表或者数据库是否存在
- Sql Server中判断表或者数据库是否存在
- Sql Server中判断表或者数据库是否存在
- Sql Server中如何判断表或者数据库的存在
- SQL Server中判断数据库是否存在
- Sql server中判断表是否存在
- SQL Server中判断一个数据库是否存在的方法
- SQL Server中判断一个数据库是否存在的方法
- SQL Server中判断一个数据库是否存在的方法
- SQL Server中如何判断一个数据库是否存在
- ASP 中判断SQLSERVER 表或者数据库是否存在
- sql server如何判断数据库是否存在
- Sql Server判断数据库、表、存储过程、函数是否存在
- Sql Server判断数据库、表、存储过程、函数是否存在
- Linux术语全称
- C#实现汉字转换为拼音缩写的代码
- awk内置字符串函数:实例
- 项目 需求分析 更新中。。。
- Java求两个数的百分比
- Sql Server中判断表或者数据库是否存在
- snmp++中的snmpGet例子,在ipv4下运行可以,ipv6下出错
- LINUX常用命令集
- LOG4NET的使用
- 安装mysql_python
- aspx/C#/asp.net 调用 非80端口的 webservice 带端口号的.
- 一些常用的正则表达式
- 在安装、重装MySQL时出现could not start the service mysql error:0的错误
- HTC S900/P3700 刷机