简体   繁体   中英

SQL Server 2016: Replicating tables generated by sp_help

I am in the process of writing a relatively large query which organizes a bunch of information on tables in my database. One thing I want to add is information on indexes and constraints on each table.

I found that sp_help 'tablename' generated two tables with basically exactly what I wanted, specifically the constraint and index tables, organized in an ideal way (all applicable keys grouped together as one bit of text, separated by commas).

Is there any simple way to either command sp_help to only pull these tables for easy access, or barring that any way to replicate the exact form of these tables with a SQL query?

It seems possible to brute force a replica of these tables without too much difficulty using a clunky mixture of sys and information_schema, but is there any minimal/elegant way to do it?

Try reading through the following blog post by Kimberly Tripp -

https://www.sqlskills.com/blogs/kimberly/sp_helpindex-v20170228/

You can download a procedure called [sp_SQLskills_helpindex], to be run as per the below -

sp_SQLskills_helpindex [TableName]

The result set can be stored in a temp table and used in whichever way you wish.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM