T-SQL query to show table definition?

后端 未结 16 1220
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-02 06:16

What is a query that will show me the full definition, including indexes and keys for a SQL Server table? I want a pure query - and know that SQL Studio can give this to me

16条回答
  •  不思量自难忘°
    2020-12-02 06:34

    "Note that I really do want the DDL that defines the table."

    use pg_dump:

    pg_dump -s -t tablename dbname
    

    It gives you the table definition (-s is schema only, no data) of a certain table ( -t tablename ) in database "dbname" in plain SQL. Additionally you will get sequence, primary key and constraint info. The output you can -maybe after checking and editing according to your needs- be fed again into (the same or another) Postgres database:

    pg_dump -s -t tablename dbname1  > /tmp/foo.sql
    psql -e dbname2 < /tmp/foo.sql
    

    This is for UNIX/Linux, but I'm sure, that a pg_dump also exists for Windows.

提交回复
热议问题