OBJECT_ID 有哪些种类



在建表建存储过程的时候经常会写到:
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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值