SQL语句判断表 数据库 数据是否存在

Sql Server中判断表或者数据库是否存在sql

if exists(select 1 from master..dbo.sysdatabases where name='example') print 'DataBase existed' else print 'Database not existed'数据库

2.表函数

IF Exists(Select 1 From sysObjects Where Name ='表名' And Type In ('S','U')) Print 'Exists Table' Else Print 'Not Exists Table'对象

Sql Server中判断表或者数据库是否存在 分类:软件开发2007.8.12 14:31 做者:stone | 评论:1 | 阅读:2996 1.数据库 if exists(select 1 from master..sysdatabases where name='example') print 'DataBase existed' else print 'Database not existed'队列

2.表开发

IF Exists(Select 1 From sysObjects Where Name ='表名' And Type In ('S','U')) Print 'Exists Table' Else Print 'Not Exists Table'string

在Sql Server2005中能够简化上述语句table

如:ast

use example扩展

go

if object_id('a','U') is not null

drop table a

go

注:a 是一个表,U表明是数据表类型

相似于U的类型代码,以下所示

对象类型:

AF = 聚合函数 (CLR)

C = CHECK 约束

D = DEFAULT(约束或独立)

F = FOREIGN KEY 约束

PK = PRIMARY KEY 约束

P = SQL 存储过程

PC = 程序集 (CLR) 存储过程

FN = SQL 标量函数

FS = 程序集 (CLR) 标量函数

FT = 程序集 (CLR) 表值函数

R = 规则(旧式,独立)

RF = 复制筛选过程

SN = 同义词

SQ = 服务队列

TA = 程序集 (CLR) DML 触发器

TR = SQL DML 触发器

IF = SQL 内联表值函数

TF = SQL 表值函数

U = 表(用户定义类型)

UQ = UNIQUE 约束

V = 视图

X = 扩展存储过程

IT = 内部表

一条sql语句判断数据是否存在 string sql = @" IF EXISTS (SELECT * FROM [表] WHERE [name]='tom') UPDATE [表] SET [age]=20 WHERE [name]='tom' ELSE BEGIN INSERT INTO [表] ([name],[age],[sex]) VALUES ('tom',20,'male') END ";

相关文章
相关标签/搜索