Find the number of columns in a table

前端 未结 19 2308
Happy的楠姐
Happy的楠姐 2020-11-27 11:13

It is possible to find the number of rows in a table:

select count(*) from tablename

Is it possible to find the number of columns in a tabl

19条回答
  •  野性不改
    2020-11-27 11:59

    Or use the sys.columns

    --SQL 2005
    SELECT  *
    FROM    sys.columns
    WHERE   OBJECT_NAME(object_id) = 'spt_values'
    -- returns 6 rows = 6 columns
    
    --SQL 2000
    SELECT  *
    FROM    syscolumns
    WHERE   OBJECT_NAME(id) = 'spt_values'
    -- returns 6 rows = 6 columns
    
    SELECT  *
    FROM    dbo.spt_values
        -- 6 columns indeed
    

提交回复
热议问题