Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



sys.sp_IHVerifyConstraint

  No additional text.


Syntax


-- Name:
--		sp_IHVerfiyConstraint

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

-- Inputs:
--		@article_id			== INPUT:	article id value
--		@constraint_name	== INPUT:	constraint name

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

-- Security:
--		Internal

-- Notes:
--		Used by scripting to validate if constraint can be created


CREATE PROCEDURE sys.sp_IHVerifyConstraint
(
	@article_id			int,
	@constraint_name	sysname
)
AS
BEGIN
	DECLARE @columnCount int
	DECLARE @idxLength   int
	DECLARE @retcode	 int
	
	-- Init retcode
	SET @retcode = 0
	
	-- Verify column count for key within SQL limits
	SELECT	@columnCount	= COUNT(*),
			@idxLength		= SUM(ihpc.length)
	FROM	dbo.IHarticles iha WITH (INDEX( idx_IHarticles_articleid)),
			dbo.IHpublisherconstraints ihpco WITH ( INDEX( idx_IHpublisherconstraints_tableid)),
			dbo.IHpublishercolumnconstraints ihpcc WITH (INDEX(idx_IHpublishercolumnconstraints_pubconstraintid)),
			dbo.IHpublishercolumns ihpc WITH (INDEX(idx_IHpublishercolumns_pubcolumnid))
	WHERE	ihpco.publisherconstraint_id	= ihpcc.publisherconstraint_id
	  AND	ihpc.publishercolumn_id			= ihpcc.publishercolumn_id
	  AND	iha.publisher_id				= ihpco.publisher_id
	  AND	iha.table_id					= ihpco.table_id
	  AND	ihpco.name						= @constraint_name
	  AND	iha.article_id					= @article_id
	OPTION  (LOOP JOIN, FORCE ORDER)
	
	IF @columnCount > 16
	BEGIN
		RAISERROR(21666, 10, 1, 16, @columnCount)
		SET @retcode = 1
	END
	
	IF @idxLength > 900
	BEGIN
		RAISERROR(21667, 10, 1, @constraint_name, @idxLength, 900)
		SET @retcode = 1
	END
		
	-- Verify key does not contain unique nullable column
	IF EXISTS
	(
		SELECT	ihpc.name
		FROM	dbo.IHarticles iha WITH (INDEX( idx_IHarticles_articleid)),
		        dbo.IHpublisherconstraints ihpco WITH ( INDEX( idx_IHpublisherconstraints_tableid)),
		        dbo.IHpublishercolumnconstraints ihpcc WITH (INDEX(idx_IHpublishercolumnconstraints_pubconstraintid)),
		        dbo.IHpublishercolumns ihpc WITH (INDEX(idx_IHpublishercolumns_pubcolumnid))
		WHERE	ihpco.publisherconstraint_id	= ihpcc.publisherconstraint_id
		  AND	ihpcc.publishercolumn_id		= ihpc.publishercolumn_id
		  AND	iha.publisher_id				= ihpco.publisher_id
		  AND	iha.table_id					= ihpco.table_id
		  AND	iha.article_id					= @article_id
		  AND	ihpco.name						= @constraint_name
		  AND	ihpc.isnullable					= 1
		  AND	ihpco.type						= 'PRIMARYKEY'
	)
	BEGIN
		RAISERROR(21665, 10, 1, @constraint_name)
		SET @retcode = 1
	END

	-- Verify all columns in constraint are published
	IF EXISTS
	(
		SELECT	ihpcc.publishercolumn_id
		FROM	dbo.IHarticles iha WITH (INDEX( idx_IHarticles_articleid)),
		  		dbo.IHpublisherconstraints ihpco WITH ( INDEX( idx_IHpublisherconstraints_tableid)),
		  		dbo.IHpublishercolumnconstraints ihpcc WITH (INDEX(idx_IHpublishercolumnconstraints_pubconstraintid))
		WHERE	ihpco.publisher_id				= iha.publisher_id
		  AND	ihpco.table_id					= iha.table_id
		  AND	ihpco.publisherconstraint_id	= ihpcc.publisherconstraint_id
		  AND	iha.article_id					= @article_id
		  AND	ihpco.name						= @constraint_name
		  AND	NOT EXISTS
		  		(
				    SELECT NULL
				    FROM   dbo.IHcolumns ih WITH (INDEX(idx_IHcolumns_articleid))
				    WHERE  ih.article_id = @article_id
				      AND  ih.publishercolumn_id = ihpcc.publishercolumn_id
				)
	)
	BEGIN
		RAISERROR(21668, 10, 1, @constraint_name)
		SET @retcode = 1
	END

	RETURN @retcode
END

 
Last revision 2008RTM
See also

  sp_IHscriptprimarykey (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