SQL Server的每个数据库内都有此系统表,它存放该数据库内创建的所有对象,如约束、默认值、日志、规则、存储过程等,每个对象在表中占一行。
以下是此系统表的字段名称和相关说明。
| 列名 | 数据类型 | 描述 |
|---|---|---|
| name | sysname | 对象名。 |
| Id | int | 对象标识号。 |
| xtype | char(2) | 对象类型。可以是下列对象类型中的一种:
C = CHECK 约束 |
| uid | smallint | 所有者对象的用户 ID。 |
| info | smallint | 保留。仅限内部使用。 |
| status | int | 保留。仅限内部使用。 |
| base_schema_ ver | int | 保留。仅限内部使用。 |
| replinfo | int | 保留。供复制使用。 |
| parent_obj | int | 父对象的对象标识号(例如,对于触发器或约束,该标识号为表 ID)。 |
| crdate | datetime | 对象的创建日期。 |
| ftcatid | smallint | 为全文索引注册的所有用户表的全文目录标识符,对于没有注册的所有用户表则为 0。 |
| schema_ver | int | 版本号,该版本号在每次表的架构更改时都增加。 |
| stats_schema_ ver | int | 保留。仅限内部使用。 |
| type | char(2) | 对象类型。可以是下列值之一:
C = CHECK 约束 |
| userstat | smallint | 保留。 |
| sysstat | smallint | 内部状态信息。 |
| indexdel | smallint | 保留。 |
| refdate | datetime | 留作以后使用。 |
| version | int | 留作以后使用。 |
| deltrig | int | 保留。 |
| instrig | int | 保留。 |
| updtrig | int | 保留。 |
| seltrig | int | 保留。 |
| category | int | 用于发布、约束和标识。 |
| cache | smallint | 保留。 |
当xtype='U' and status>0代表是用户建立的表,对象名就是表名,对象ID就是表的ID值。
用以下代码就可以列出库misa中所有的用户建立的表名。
select * from misa.dbo.sysobjects
where xtype='U'and status>0
--查询数据库ufdata_888_2004的用户表
select * from sysobjects
where xtype = 'u' and name like 'fa_%'
order by name
--查询数据库ufdata_888_2004的存储过程
select * from sysobjects
where xtype = 'p' and name like 'fa_%'
order by name
--查询数据库ufdata_888_2004的触发器
select * from sysobjects
where xtype = 'tr' and name like 'sa_%'
order by name
查询表名为tb_menu的所有列名
1
select name from syscolumns where id=object_id('tb_menu')
查询表名为tb_menu的所有列名个数
2
select count(name) from syscolumns where id=object_id('tb_menu')
或者
3
select count(syscolumns.name)
from syscolumns ,sysobjects
where syscolumns.id=sysobjects.id and sysobjects.name = 'tb_menu'
本文深入解析了SQLServer系统表的基本结构及其关键字段,详细讲解了如何通过系统表查询数据库中的各类对象,包括表、存储过程、触发器等,并提供了具体的SQL查询代码示例。
427

被折叠的 条评论
为什么被折叠?



