T-SQL query to show table definition?

后端 未结 16 1231
爱一瞬间的悲伤
爱一瞬间的悲伤 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条回答
  •  Happy的楠姐
    2020-12-02 06:29

    A variation of @Anthony Faull's answer for those using LINQPad:

    new Server(new ServerConnection(this.Connection.DataSource))
        .Databases[this.Connection.Database]
        .Tables["", "dbo"]
        ?.Script(new ScriptingOptions {
            SchemaQualify = true,
            DriAll = true,
        })
    

    You'll need to reference 2 assemblies:

    • Microsoft.SqlServer.ConnectionInfo.dll
    • Microsoft.SqlServer.Smo.dll

    And add namespace references as mentioned in Anthony's snippet.

    提交回复
    热议问题