SQL SERVER 中的 object_id()函数
2015-10-10 16:24
423 查看
在SQLServer数据库中,如果查询数据库中是否存在指定名称的索引或者外键约束等,经常会用到object_id('name','type')方法,做笔记如下:
?
语法:object_id('objectname')或object('objectname','type')
作用:该函数会返回指定对象的ID值,可以在sysobjects表中进行验证。
其中objectname数据类型为 char 或 nchar。如果 object 的数据类型是 char,那么隐性将其转换成 nchar。
type如下列表:
AF = Aggregate function (CLR)
C = CHECK constraint
D = DEFAULT (constraint or stand-alone)
F = FOREIGN KEY constraint
FN = SQL scalar function
FS = Assembly (CLR) scalar-function
FT = Assembly (CLR) table-valued function
IF = SQL inline table-valued function
IT = Internal table
P = SQL Stored Procedure
PC = Assembly (CLR) stored-procedure
PG = Plan guide
PK = PRIMARY KEY constraint
R = Rule (old-style, stand-alone)
RF = Replication-filter-procedure
S = System base table
SN = Synonym
SQ = Service queue
TA = Assembly (CLR) DML trigger
TF = SQL table-valued-function
TR = SQL DML trigger
U = Table (user-defined)
UQ = UNIQUE constraint
V = View
X = Extended stored procedure
?
例子如下:
select object_id('fk_xxx_xx','F')会取出约束名为fk_xxx_xx的ID值,如返回144444444这个值。
上面的语句等同:
select ID from sysobjects where name='fk_xxx_xx' and type='F'
=======================================================================================
大家都知道在数据库中有一个系统表sysobjects,里面存储了数据库各个对象的信息。可以查询下看看结果。可以看出每个对象都有一个ID,这个表存储了表,存储过程,触发器,视图等相关信息。注意:字段没有。
object_id就是根据对象名称返回该对象的id.
object_name是根据对象id返回对象名称.
select object_id(对象名)等同于:
select id from sysobjects where
name=对象名
select object_name(id号)等同于:
select name from sysobjects where id=id号
SQL SERVER
2000以上版本都支持这个函数。
?
语法:object_id('objectname')或object('objectname','type')
作用:该函数会返回指定对象的ID值,可以在sysobjects表中进行验证。
其中objectname数据类型为 char 或 nchar。如果 object 的数据类型是 char,那么隐性将其转换成 nchar。
type如下列表:
AF = Aggregate function (CLR)
C = CHECK constraint
D = DEFAULT (constraint or stand-alone)
F = FOREIGN KEY constraint
FN = SQL scalar function
FS = Assembly (CLR) scalar-function
FT = Assembly (CLR) table-valued function
IF = SQL inline table-valued function
IT = Internal table
P = SQL Stored Procedure
PC = Assembly (CLR) stored-procedure
PG = Plan guide
PK = PRIMARY KEY constraint
R = Rule (old-style, stand-alone)
RF = Replication-filter-procedure
S = System base table
SN = Synonym
SQ = Service queue
TA = Assembly (CLR) DML trigger
TF = SQL table-valued-function
TR = SQL DML trigger
U = Table (user-defined)
UQ = UNIQUE constraint
V = View
X = Extended stored procedure
?
例子如下:
select object_id('fk_xxx_xx','F')会取出约束名为fk_xxx_xx的ID值,如返回144444444这个值。
上面的语句等同:
select ID from sysobjects where name='fk_xxx_xx' and type='F'
=======================================================================================
大家都知道在数据库中有一个系统表sysobjects,里面存储了数据库各个对象的信息。可以查询下看看结果。可以看出每个对象都有一个ID,这个表存储了表,存储过程,触发器,视图等相关信息。注意:字段没有。
object_id就是根据对象名称返回该对象的id.
object_name是根据对象id返回对象名称.
select object_id(对象名)等同于:
select id from sysobjects where
name=对象名
select object_name(id号)等同于:
select name from sysobjects where id=id号
SQL SERVER
2000以上版本都支持这个函数。
相关文章推荐
- 我学习Object-C中的收获总结(一)(二)
- OC之非正式协议总结
- Objective-C 对 URL 进行 URLEncode 编码
- # xamarin 自动绑定工具sharpie使用介绍
- Objective-C 计算代码运行时间
- linq to object
- NSdata 与 NSString,Byte数组,UIImage 的相互转换—ios开发 Objective-C
- IOS加强知识(1)理解力Objective-C
- a different object with the same identifier value was already associated with the session
- Object-c父类子类
- Object-c 对象的使用和定义
- Object-C总结
- Python中用json.loads解码字符串出错:ValueError: No JSON object could be decoded
- 【Objective-C学习笔记】变量和基本的数据类型
- [Objective-c]_[NSUserDefaults]_[基本使用]
- 黑马程序员-----------Objective-C基础-----------OC基础
- C#中object missing = Type.Missing是什么意思
- shared libraries: libgtest.so.0: cannot open shared object fi
- Attempt to read from field 'int android.view.View.mViewFlags' on a null object reference
- [Objective-c]_[块语法的使用及应用场景]