Describe table structure

前端 未结 13 2198
北恋
北恋 2020-12-23 15:37

Which query will give the table structure with column definitions in SQL?

相关标签:
13条回答
  • 2020-12-23 16:12
    DESCRIBE tableName
    

    Check MySQL describe command

    0 讨论(0)
  • 2020-12-23 16:18

    It depends from the database you use. Here is an incomplete list:

    • sqlite3: .schema table_name
    • Postgres (psql): \d table_name
    • SQL Server: sp_help table_name (or sp_columns table_name for only columns)
    • Oracle DB2: desc table_name or describe table_name
    • MySQL: describe table_name (or show columns from table_name for only columns)
    0 讨论(0)
  • 2020-12-23 16:19

    sp_help tablename in sql server -- sp_help [ [ @objname = ] 'name' ]

    desc tablename in oracle -- DESCRIBE { table-Name | view-Name }

    0 讨论(0)
  • 2020-12-23 16:20

    Sql server

    DECLARE @tableName nvarchar(100)
    SET @tableName = N'members' -- change with table name
    SELECT
        [column].*,
        COLUMNPROPERTY(object_id([column].[TABLE_NAME]), [column].[COLUMN_NAME], 'IsIdentity') AS [identity]
    FROM 
        INFORMATION_SCHEMA.COLUMNS [column] 
    WHERE
        [column].[Table_Name] = @tableName
    
    0 讨论(0)
  • 2020-12-23 16:21

    For SQL, use the Keyword 'sp_help'

    0 讨论(0)
  • 2020-12-23 16:25

    This depends on your database vendor. Mostly it's the "information schema" you should Google for (applies to MySQL, MSSQL and perhaps others).

    0 讨论(0)
提交回复
热议问题