Where do I find Sql Server metadata for column datatypes?

前端 未结 3 1755
礼貌的吻别
礼貌的吻别 2021-01-11 09:52

I know that I can get access to column properties via:

select * 
from sysobjects

What I can\'t find however is information about where to g

3条回答
  •  暖寄归人
    2021-01-11 10:16

    You are close. You can look at sys.columns to get the columns.

    You can filter on a table with OBJECT_ID=OBJECT_ID('dbo.Foo').

    You can get the length from sys.columns. The data type is in the system_type field. The keys for that field are in sys.types.

    In its entirety you can do:

    select object_NAME(c.object_id), c.name, t.name, c.max_length
    from sys.columns c
    INNER JOIN sys.types t
        ON t.system_type_id = c.system_type_id
    

    As a side note, in SQL Server the system tables are deprecated (i.e. syscolumns, sysobjects) and it's recommended as a best practice to use the views instead, sys.columns, sys.objects, etc.

    This will give you Table, column, data type, and maxlength for each one.

提交回复
热议问题