Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



sys.sp_IHVerifyIndex

  No additional text.


Syntax


-- Name:
--		sp_IHVerifyIndex

-- Description:
--		Verify index can be created in SQL Server

-- Inputs:
--		@article_id	== INPUT:	article id value
--		@index_name	== INPUT:	index name

-- Returns:
--		Return code (0 for success, 1 for failure)

-- Security:
--		Internal

-- Notes:
--		Used by scripting to validate if an index
--		can be created for an article


CREATE PROCEDURE sys.sp_IHVerifyIndex
(
	@article_id		int,
	@index_name		sysname
)
AS
BEGIN
	DECLARE @columnCount int
	DECLARE @idxLength   int
	DECLARE @retcode	 int
	
	-- Init retcode
	SET @retcode = 0
	
	-- Verify column count for indexes within SQL limits
	SELECT	@columnCount	= COUNT(*),
			@idxLength		= SUM(ihpc.length)
	FROM	dbo.IHpublisherindexes ihpi,
			dbo.IHpublishercolumnindexes ihpci,
			dbo.IHpublishercolumns ihpc,
			dbo.IHarticles iha
	WHERE	ihpi.publisherindex_id		= ihpci.publisherindex_id
	  AND	ihpci.publishercolumn_id	= ihpc.publishercolumn_id
	  AND	iha.publisher_id			= ihpi.publisher_id
	  AND	iha.table_id				= ihpi.table_id
	  AND	iha.article_id				= @article_id
	  AND	ihpi.name					= @index_name

	IF @columnCount > 16
	BEGIN
		RAISERROR(21666, 10, 1, 16, @columnCount)
		SET @retcode = 1
	END
	
	IF @idxLength > 900
	BEGIN
		RAISERROR(21667, 10, 1, @index_name, @idxLength, 900)
		SET @retcode = 1
	END
		
	-- Verify index does not contain unique nullable column
	IF EXISTS
	(
		SELECT	ihpc.name
		FROM	dbo.IHpublisherindexes ihpi,
				dbo.IHpublishercolumnindexes ihpci,
				dbo.IHpublishercolumns ihpc,
				dbo.IHarticles iha
		WHERE	ihpi.publisherindex_id		= ihpci.publisherindex_id
		  AND	ihpci.publishercolumn_id	= ihpc.publishercolumn_id
		  AND	iha.publisher_id			= ihpi.publisher_id
		  AND	iha.table_id				= ihpi.table_id
		  AND	iha.article_id				= @article_id
		  AND	ihpi.name					= @index_name
		  AND	ihpi.type					= 'UNIQUE'
		  AND	ihpc.isnullable				= 1
	)
	BEGIN
		RAISERROR(21664, 10, 1, @index_name)
		SET @retcode = 1
	END

	-- Verify all columns in index are published
	IF EXISTS
	(
		SELECT	ihpci.publishercolumn_id
		FROM	dbo.IHpublisherindexes ihpi,
				dbo.IHpublishercolumnindexes ihpci,
				dbo.IHarticles iha
		WHERE	ihpi.publisher_id		= iha.publisher_id
		  AND	ihpi.table_id			= iha.table_id
		  AND	ihpi.publisherindex_id	= ihpci.publisherindex_id
		  AND	iha.article_id			= @article_id
		  AND	ihpi.name				= @index_name
		  AND	ihpci.publishercolumn_id NOT IN
		  		(
					SELECT	publishercolumn_id
					FROM	dbo.IHcolumns
					WHERE	article_id = @article_id
				)
	)
	BEGIN
		RAISERROR(21668, 10, 1, @index_name)
		SET @retcode = 1
	END

	RETURN @retcode
END

 
Last revision 2008RTM
See also

  sp_IHscriptindexes (Procedure)
sp_MSdrop_repltran (Procedure)
       



News

  Query a named instance
Sybase+ASE+silent+install
SQL 2008 R2
Deprecated procedures in SQL2008
Reporting Services item-level role definitions
Create all your missing indexes
Converting datetime field
Start MSSQL Server Profiler at time
Replicating MSSQL Server views
Exploring Microsoft Sharepoint
The OLE DB provider "SQLNCLI10" for linked server indicates.
Mobile solar charger
Oracle to SQL Server replication
Cannot insert the value NULL into column
Undocumented Microsoft SQL Server 2008
VMware
Zoekmachine optimalisatie
SQL Servers hidden objects
FckEditor
Flash in Ajax
De hype die AJAX heet
Barcode scannen
MySQL; Gratis, makkelijk en snel!
PHP
sIFR; de combinatie tussen HTML en Flash