[英]How can I complete my current query about User Defined Table Types and getting Schema,IsIdentity,IsPrimaryKey and …?
I have a query for getting information about User Defined Table Types. 我有一个查询来获取有关用户定义的表类型的信息。
I need to complete this query by adding the following columns : 我需要通过添加以下列来完成此查询:
IsIdentity
IsPrimaryKey
Schema
ColumnDefaultValue
The query: 查询:
SELECT o.name AS TableName ,
c.name AS ColumnName ,
c.isnullable AS [IsNullable] ,
t.name AS [DataType] ,
t.[length] AS [MaxLength] ,
t.prec AS [Precision]
FROM syscolumns c
INNER JOIN sysobjects o ON o.id = c.id
LEFT JOIN systypes t ON t.xtype = c.xtype
WHERE c.id IN ( SELECT type_table_object_id
FROM sys.table_types )
ORDER BY o.name ,
c.name;
And I have another question about the above query. 我有关于上述查询的另一个问题。
I have User Defined Table Types with dbo.MyType
as name but in this query it shows me 'TT_MyType_37C5420D'. 我有用户定义的表类型,
dbo.MyType
作为名称,但在此查询中它显示'TT_MyType_37C5420D'。
How can I get the real name ? 我怎样才能得到真名?
You should use the new catalog views from the sys
schema as of SQL Server 2005 and avoid the old syscolumns
, sysobjects
etc. 您应该从SQL Server 2005开始使用
sys
模式中的新目录视图,并避免使用旧的syscolumns
, sysobjects
等。
When rewriting your query to this: 将查询重写为此时:
SELECT
tt.name AS TableName,
c.name AS ColumnName,
c.is_nullable AS [IsNullable],
c.is_identity,
t.name AS [DataType],
t.max_length [MaxLength],
t.precision AS [Precision]
FROM
sys.table_types tt
INNER JOIN
sys.columns c ON c.object_id = tt.type_table_object_id
LEFT JOIN
sys.types t ON t.system_type_id = c.system_type_id
ORDER BY
tt.name, c.name;
you can easily tap into the more extensive information available in the sys
catalog view - like the c.is_identity
column on sys.columns
. 您可以轻松使用
sys
目录视图中提供的更广泛的信息 - 例如sys.columns
上的c.is_identity
列。 And also - the name
from sys.table_types
seems to return the more humanly readable name as you were looking for. 而且 - 来自
sys.table_types
的name
似乎返回了您正在寻找的更易读的名称。
Check out the very extensive MSDN documentation on the sys
catalog views do discover a lot more information you might be interested in 查看
sys
目录视图中非常广泛的 MSDN文档,确实发现了您可能感兴趣的更多信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.