Answered Questions

  • What is DESCRIBE command in SQL Server?

    What is its purpose?How to use it?

    Star Read Best Answer

    Editorial / Best Answer

    suji  

    • Member Since Sep-2005 | Nov 5th, 2011


    Here are multiple ways to get the table information. The DESCRIBE command does not exist in MS SQL SERVER. This is an Oracle command used to describe the structure of objects within a given database. To achieve the same task in MSSQL Server, there are a series of stored procedures with the prefix SP_ that can be used. To view the structure of a table within the current database, use the command

    Code
    1. sp_help 'TABLE_NAME';
    If you would like to see more details, Create your custom procedure
    Code
    1. CREATE procedure DESCRIBE
    2. (
    3. @tablename varchar(256)
    4. )
    5. AS
    6. begin
    7. SELECT DISTINCT sCols.colid AS 'order', sCols.name, sTyps.name, sCols.length
    8. FROM [syscolumns] sCols
    9. INNER JOIN [systypes] sTyps ON sCols.xtype = sTyps.xtype
    10. INNER JOIN [sysobjects] sObjs ON sObjs.id = sCols.[id]
    11. AND UPPER(sObjs.name) = UPPER(@tablename)
    12. ORDER BY sCols.colid
    13. end
    Here is another alternative way to get the same information
    Code
    1. sp_columns 'TableName' (e.g. sp_columns 'Employee')
    2. sp_columns [ @table_name = ] object [ , [ @table_owner = ] owner ]
    3. [ , [ @table_qualifier = ] qualifier ]
    4. [ , [ @column_name = ] COLUMN ]
    5. [ , [ @ODBCVer = ] ODBCVer ]
    Here is the usage :
    Code
    1. EXEC sp_columns @table_name = 'Department', @table_owner = 'sa';
    2. SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'TableName'
    Contributors for the editorial answer : Kewlshiva, srilakshmi.b, raaghav,kevaburg

    Rooshi

    • Oct 17th, 2014

    Sp_help will give all the details about the table columns, indexes, partitions etc.

    Saket Kale

    • Oct 24th, 2012

    Sp_help dbo.customers;

    worked for me just fine.

    Thanks to the OP, this runs perfectly on SQL 2008 R2, do not know about other versions