我有这样的查询:
SELECT TABLE_NAME, COLUMN_NAME, IS_NULLABLE, DATA_TYPE FROM MY_DB.INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME = 'OrderId' ORDER BY TABLE_NAME GO
该OrderId
列是用户定义的数据类型.但是DATA_TYPE
在查询中显示了底层系统类型(即bigint).如何显示用户定义的类型名称?
您可以更改Where子句:
SELECT c.name as ColumneName, c.colid As ColumnOrder, st.name as UserType, bt.name as BaseType FROM dbo.syscolumns c INNER JOIN dbo.systypes st ON st.xusertype = c.xusertype INNER JOIN dbo.systypes bt ON bt.xusertype = c.xtype WHERE c.id = OBJECT_ID('TableName') ORDER BY c.colid
编辑 - 更完整的版本 - 享受!
SELECT OBJECT_NAME(c.id) as TableName, c.name as ColumnName, c.colid As ColumnOrder, st.name as UserType, bt.name as BaseType FROM dbo.syscolumns c INNER JOIN dbo.systypes st ON st.xusertype = c.xusertype INNER JOIN dbo.systypes bt ON bt.xusertype = c.xtype WHERE OBJECTPROPERTY(c.id,'ISTABLE') = 1 AND c.name = 'ColumnName' ORDER BY OBJECT_NAME(c.id), c.colid