T-SQL query to show table definition?

后端 未结 16 1271
爱一瞬间的悲伤
爱一瞬间的悲伤 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:47

    This will return columns, datatypes, and indexes defined on the table:

    --List all tables in DB
    select * from sysobjects where xtype = 'U'
    
    --Table Definition
    sp_help TableName
    

    This will return triggers defined on the table:

    --Triggers in SQL Table
    select * from sys.triggers where parent_id = object_id(N'SQLTableName') 
    

提交回复
热议问题