sqlserver查询数据库中有多少个表,多少视图,多少存储过程,或其他对象

--sql server 数表:
select count(1) from sysobjects where xtype='U'
--数视图:
select count(1) from sysobjects where xtype='V'
--数存储过程
select count(1) from sysobjects where xtype='P'
SELECT * FROM sysobjects WHERE (xtype = 'U')

--C = CHECK 约束 
--D = 默认值或 DEFAULT 约束 
--F = FOREIGN KEY 约束 
--L = 日志 
--FN = 标量函数 
--IF = 内嵌表函数 
--P = 存储过程 
--PK = PRIMARY KEY 约束(类型是 K) 
--RF = 复制筛选存储过程 
--S = 系统表 
--TF = 表函数 
--TR = 触发器 
--U = 用户表 
--UQ = UNIQUE 约束(类型是 K) 
--V = 视图 
--X = 扩展存储过程

SQL Server xtype的介绍

在数据库内创建的每个对象(约束、默认值、日志、规则、存储过程等)在表中占一行。只有在 tempdb 内,每个临时对象才在该表中占一行。

列名数据类型描述
namesysname对象名,常用列
idint对象标识号
xtypechar(2)对象类型。常用列。xtype可以是下列对象类型中的一种:
AF = Aggregate function (CLR)
C = CHECK constraint
D = Default or DEFAULT constraint
F = FOREIGN KEY constraint
L = Log
FN = Scalar function
FS = Assembly (CLR) scalar-function
FT = Assembly (CLR) table-valued function
IF = In-lined table-function
IT = Internal table
P = Stored procedure
PC = Assembly (CLR) stored-procedure
PK = PRIMARY KEY constraint (type is K)
RF = Replication filter stored procedure
S = System table
SN = Synonym
SQ = Service queue
TA = Assembly (CLR) DML trigger
TF = Table function
TR = SQL DML Trigger
TT = Table type
U = User table
UQ = UNIQUE constraint (type is K)
V = View
X = Extended stored procedure
uidsmallintSchema ID of the owner of the object. For databases upgraded from an earlier version of SQL Server, the schema ID is equal to the user ID of the owner. Overflows or returns NULL if the number of users and roles exceeds 32,767.
** Important ** If you use any of the following SQL Server DDL statements, you must use the sys.objects catalog view instead of sys.sysobjects.
CREATE | ALTER | DROP USER
CREATE | ALTER | DROP ROLE
CREATE | ALTER | DROP APPLICATION ROLE
CREATE SCHEMA
ALTER AUTHORIZATION ON OBJECT
infosmallintIdentified for informational purposes only. Not supported. Future compatibility is not guaranteed.
statusintIdentified for informational purposes only. Not supported. Future compatibility is not guaranteed.
base_schema_verintIdentified for informational purposes only. Not supported. Future compatibility is not guaranteed.
replinfointIdentified for informational purposes only. Not supported. Future compatibility is not guaranteed.
parent_objintObject identification number of the parent object. For example, the table ID if it is a trigger or constraint.
crdatedatetimeDate the object was created.
ftcatidsmallintIdentifier of the full-text catalog for all user tables registered for full-text indexing, and 0 for all user tables that are not registered.
schema_verintVersion number that is incremented every time the schema for a table changes. Always returns 0.
stats_schema_verintIdentified for informational purposes only. Not supported. Future compatibility is not guaranteed.
typechar(2)Object type. Can be one of the following values:
AF = Aggregate function (CLR)
C = CHECK constraint
D = Default or DEFAULT constraint
F = FOREIGN KEY constraint
FN = Scalar function
FS = Assembly (CLR) scalar-function
FT = Assembly (CLR) table-valued functionIF = In-lined table-function
IT - Internal table
K = PRIMARY KEY or UNIQUE constraint
L = Log
P = Stored procedure
PC = Assembly (CLR) stored-procedure
R = Rule
RF = Replication filter stored procedure
S = System table
SN = Synonym
SQ = Service queue
TA = Assembly (CLR) DML trigger
TF = Table function
TR = SQL DML Trigger
TT = Table type
U = User table
V = View
X = Extended stored procedure
userstatsmallintIdentified for informational purposes only. Not supported. Future compatibility is not guaranteed.
sysstatsmallintIdentified for informational purposes only. Not supported. Future compatibility is not guaranteed.
indexdelsmallintIdentified for informational purposes only. Not supported. Future compatibility is not guaranteed.
refdatedatetimeIdentified for informational purposes only. Not supported. Future compatibility is not guaranteed.
versionintIdentified for informational purposes only. Not supported. Future compatibility is not guaranteed.
deltrigintIdentified for informational purposes only. Not supported. Future compatibility is not guaranteed.
instrigintIdentified for informational purposes only. Not supported. Future compatibility is not guaranteed.
updtrigintIdentified for informational purposes only. Not supported. Future compatibility is not guaranteed.
seltrigintIdentified for informational purposes only. Not supported. Future compatibility is not guaranteed.
categoryintUsed for publication, constraints, and identity.
cachesmallintIdentified for informational purposes only. Not supported. Future compatibility is not guaranteed.
列名数据类型描述
namesysname对象名,常用列
idint对象标识号
xtypechar(2)对象类型。常用列。xtype可以是下列对象类型中的一种:
C = CHECK 约束  D = 默认值或 DEFAULT 约束  F = FOREIGN KEY 约束  L = 日志  FN = 标量函数
IF = 内嵌表函数   P = 存储过程   PK = PRIMARY KEY 约束(类型是 K)   RF = 复制筛选存储过程
S = 系统表   TF = 表函数   TR = 触发器   U = 用户表   UQ = UNIQUE 约束(类型是 K)
V = 视图   X = 扩展存储过程
uidsmallint所有者用户对象编号
infosmallint保留。仅限内部使用
statusint保留。仅限内部使用
base_schema_ verint保留。仅限内部使用
replinfoint保留。供复制使用
parent_objint父对象的对象标识号(例如,对于触发器或约束,该标识号为表 ID)。
crdatedatetime对象的创建日期。
ftcatidsmallint为全文索引注册的所有用户表的全文目录标识符,对于没有注册的所有用户表则为 0
schema_verint版本号,该版本号在每次表的架构更改时都增加。
stats_schema_ verint保留。仅限内部使用。
typechar(2)对象类型。可以是下列值之一:
C = CHECK 约束 D = 默认值或 DEFAULT 约束 F = FOREIGN KEY 约束
FN = 标量函数 IF = 内嵌表函数 K = PRIMARY KEY 或 UNIQUE 约束
L = 日志 P = 存储过程 R = 规则 RF = 复制筛选存储过程
S = 系统表 TF = 表函数 TR = 触发器 U = 用户表 V = 视图 X = 扩展存储过程
userstatsmallint保留。
sysstatsmallint内部状态信息
indexdelsmallint保留
refdatedatetime留用
versionint保留
deltrigint保留
instrigint保留
updtrigint保留
seltrigint保留
categoryint用于发布、约束和标识
cachesmallint保留

可以很方便的用

select * from sysobjects where xtype='TR' and parent_obj=object_id('表名')

查出表的信息

syscolumns表内的xtype

查了一下,这些东西都是存于每一个数据库的syscolumns表里面得,name就是列名,xtype就是数据类型,但是这个xtype是数字的,下面是数字和数据类型对应的关系;

 xtype=34 'image'
 xtype= 35 'text'
 xtype=36 'uniqueidentifier'
 xtype=48 'tinyint'
 xtype=52 'smallint'
 xtype=56 'int'
 xtype=58 'smalldatetime'
 xtype=59 'real'
 xtype=60 'money'
 xtype=61 'datetime'
 xtype=62 'float'
 xtype=98 'sql_variant'
 xtype=99 'ntext'
 xtype=104 'bit'
 xtype=106 'decimal'
 xtype=108 'numeric'
 xtype=122 'smallmoney'
 xtype=127 'bigint'
 xtype=165 'varbinary'
 xtype=167 'varchar'
 
 xtype=173 'binary'
 xtype=175 'char'
 xtype=189 'timestamp'
 xtype=231 'nvarchar'
 
 xtype=239 'nchar'
 xtype=241 'xml'
 xtype=231 'sysname'
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值