查询以查找表定义

时间:2013-08-16 13:13:01

标签: sql tsql

我刚刚在tsql中创建了一个表,但现在我希望能够得到该表的定义,比如列名,无论是int还是nvarchar或者它是什么参数,是否为null等等。这是什么tsql查询?

2 个答案:

答案 0 :(得分:0)

您可以查询架构,如下所示:

SELECT 
   ORDINAL_POSITION,
   DATA_TYPE,
   CHARACTER_MAXIMUM_LENGTH,
   IS_NULLABLE,
   COLUMN_DEFAULT
FROM   
   INFORMATION_SCHEMA.COLUMNS 
WHERE   
   TABLE_NAME = 'Product' 
ORDER BY 
   ORDINAL_POSITION ASC; 

答案 1 :(得分:0)

SELECT 
    ColumnName  = C.Name
,   ColumnSeq   = C.column_id
,   DataType    = T.name
,   MaxLength   = C.max_length
,   Percision   = C.precision
,   Scale       = c.scale
,   IsNullable  = C.Is_nullable
,   IsIdentiy   = C.Is_identity
,   Colation    = c.collation_name
FROM sys.Columns C
JOIN sys.Types T ON T.System_Type_id = C.System_Type_id
where c.object_id = object_id('dbo.product')
order by c.column_id