根据sysobjects 文档,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