日期:2014-05-17 浏览次数:20779 次
/*============================================================================
File: sp_helpindex2.sql
Summary: So, what are the included columns?!
This is a MODIFIED sp_helpindex script that includes INCLUDEd
columns.
Date: August 2008
SQL Server *2005* Version: tested on 9.00.3068.00 (SP2+ GDRs)
------------------------------------------
Written by Kimberly L. Tripp, SYSolutions, Inc.
(with tweaks/fixes from blog readers! THANKS!!)
For more scripts and sample code, check out
http://www.SQLskills.com
This script is intended only as a supplement to demos and lectures
given by SQLskills instructors.
THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
============================================================================*/
USE master
go
IF OBJECTPROPERTY(object_id('sp_helpindex2'), 'IsProcedure') = 1
DROP PROCEDURE sp_helpindex2
go
create procedure sp_helpindex2
@objname nvarchar(776) -- the table to check for indexes
as
-- April 2008: Updated to add included columns to the output.
-- August 2008: Fixed a bug (missing begin/end block) AND I found
-- a few other issues that people hadn't noticed (yikes!)!
-- See Kimberly's blog for updates and/or additional information
-- http://www.SQLskills.com/blogs/Kimberly
-- PRELIM
set nocount on
declare @objid int, -- the object id of the table
@indid smallint, -- the index id of an index
@groupid int, -- the filegroup id of an index
@indname sysname,
@groupname sysname,
@status int,
@keys nvarchar(2126), --Length (16*max_identifierLength)+(15*2)+(16*3)
@inc_columns nvarchar(max),
@inc_Count smallint,
@loop_inc_Count smallint,
@dbname sysname,
@ignore_dup_key bit,
@is_unique bit,
@is_hypothetical bit,
@is_primary_key bit,
@is_unique_key bit,
@auto_created bit,
@no_recompute bit
-- Check to see that the object names are local to the current database.
select @dbname = parsename(@objname,3)
if @dbname is null
select @dbname&n