T-SQL query to show table definition?

后端 未结 16 1269
爱一瞬间的悲伤
爱一瞬间的悲伤 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条回答
  •  猫巷女王i
    2020-12-02 06:41

    Visit http://www.stormrage.com/SQLStuff/sp_GetDDL_Latest.txt.

    You will find the code of sp_getddl procedure for SQL Server. The purpose of the procedure is script any table, temp table or object.

    USAGE:

    exec sp_GetDDL GMACT
    

    or

    exec sp_GetDDL 'bob.example'
    

    or

    exec sp_GetDDL '[schemaname].[tablename]'
    

    or

    exec sp_GetDDL #temp
    

    I tested it on SQL Server 2012, and it does an excellent job.

    I'm not the author of the procedure. Any improvement you make to it send to Lowell Izaguirre (scripts@stormrage.com).

提交回复
热议问题