新闻  |   论坛  |   博客  |   在线研讨会
OBJECT_ID 有哪些种类
luker | 2017-04-10 09:56:46    阅读:1280   发布文章

特别是在建表建存储过程的时候进场会写到:

IF OBJECT_ID('Table_Test','U') IS NOT NULL DROP TABLE Table_Test

这种方式代替了以往所使用的

IF EXISTS (SELECT * FROM SYSOBJECTS WHERE NAME = 'Table_Test') DROP TABLE Table_Test

第一段代码中的 U 可以省略不写, 这样系统就会检索所有的对象名称以找到对应的ID, 但是写出来就可以更加明确是哪一种类型,筛选的范围要小很多.
以下列出全部 Object 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

TT = Table type

U = Table (user-defined)

UQ = UNIQUE constraint

V = View

X = Extended stored procedure

可以通过这个查询语句获取当前数据库中各个数据库表,视图,存储过程等数量。

SELECT CASE TYPE WHEN 'U' THEN 'User Defined Tables' WHEN 'V' THEN 'View' WHEN 'S' THEN 'System Tables' WHEN 'IT' THEN 'Internal Tables' WHEN 'P' THEN 'Stored Procedures' WHEN 'PC' THEN 'CLR Stored Procedures' WHEN 'X' THEN 'Extended Stored Procedures' WHEN 'FN' THEN 'Scalar-valued Functions' WHEN 'IF' THEN 'Table-valued Functions' END AS Objects, COUNT(*) AS Counts FROM SYS.OBJECTS WHERE TYPE IN ('U','V','S','IT','P','PC','X','FN','IF') GROUP BY TYPE

*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。

参与讨论
登录后参与讨论
推荐文章
最近访客