2013-04-26 40 views
10

the sysobjects documentation,可以是下列对象类型中的一种:是否有一张表包含sysobjects.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 

回答

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 
+0

意想不到的答案!我用最终结果编辑了我的问题,因为'join'与标准有点不同,所以每个人都可以清楚地了解我是如何加入的。 – 2013-04-26 19:42:44