是否有一个表包含sysobjects.xtype描述的列表?

时间:2013-04-26 19:30:10

标签: sql sql-server sql-server-2008

根据the sysobjects documentationsysobjects.xtype可以是以下对象类型之一:

| xtype |              Description              |
|-------|---------------------------------------|
| 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            |

我可以将它们放入CASE语句中,但是我可以加入一个表来查找xtype描述吗?我知道systypes不是那张桌子。我的意思是,我只是记住了很多,但我正在对数据库进行一些研究,这对我来说很陌生(即我对此并不了解)所以我想建立没有CASE语句的对此查询的描述:

select object_name(c.id), c.name, [length], o.xtype from syscolumns c
    join sysobjects o on o.id = c.id
where c.name like '%job%code%'
更新

以下是SQLMenace回答后的最终结果。我认为有必要放在这里因为它不仅仅是一个直接的join

select object_name(c.id), c.name, t.name, c.[length], o.xtype, x.name from syscolumns c
    join sysobjects o on o.id = c.id
    join systypes t on t.xtype = c.xtype
    join master..spt_values x on x.name like '%' + o.xtype + '%' and x.type = 'O9T'
where c.name like '%job%code%'
order by c.xtype

2 个答案:

答案 0 :(得分:11)

有这个

SELECT name 
FROM master..spt_values
WHERE type = 'O9T'

输出

AF: aggregate function
AP: application
C : check cns
D : default (maybe cns)
EN: event notification
F : foreign key cns
FN: scalar function
FS: assembly scalar function
FT: assembly table function
IF: inline function
IS: inline scalar function
IT: internal table
L : log
P : stored procedure
PC : assembly stored procedure
PK: primary key cns
R : rule
RF: replication filter proc
S : system table
SN: synonym
SQ: queue
TA: assembly trigger
TF: table function
TR: trigger
U : user table
UQ: unique key cns
V : view
X : extended stored proc
sysobjects.type, reports

答案 1 :(得分:0)

这是我想出的总数数据库对象及其描述。

    select xtype1, Description, total_count, last_crdate, last_refdate 
    from 
    (SELECT xtype as xtype1, total_count = COUNT(*), last_crdate = MAX(crdate), last_refdate = MAX(refdate)
     FROM sysobjects 
     GROUP BY xtype
     )o
    left outer join 
    (SELECT LEFT(name,PATINDEX('%:%',name)-1) AS xtype2, RIGHT(name, (LEN(name) - PATINDEX('%:%',name))) AS Description
    FROM master..spt_values 
    WHERE type = 'O9T' AND number  = -1
    )x 
    on o.xtype1 = x.xtype2
    order by Description;