bluebunny72 icon

ISO Country Code unique index

bluebunny72 | PRO | 07/22/16 11:51:51 PM UTC | 0 ⭐ | 496 👁️ | Never ⏰ | []
SQL |

1.02 KB

|

None

|

0 👍

/

0 👎

IF NOT EXISTS(SELECT TOP 1 1 FROM sys.indexes WHERE name = 'IX_ILC_country_iso_country_code')
  BEGIN
    CREATE UNIQUE NONCLUSTERED INDEX IX_ILC_country_iso_country_code
    ON dbo.country(iso_country_code ASC)
    WHERE iso_country_code IS NOT NULL;
  END
  
GO
 
IF NOT EXISTS (SELECT TOP 1 1 FROM ObjectMainMessages WHERE ObjectName = 'IX_ILC_country_iso_country_code' AND MessageType = 17)
    BEGIN
        DECLARE @NextMessageNo  INT
 
        SELECT @NextMessageNo   = ISNULL(MAX(messageno),799999) 
        FROM ApplicationMessages 
        WHERE MessageNo BETWEEN 800000 AND 999999
 
        SET @NextMessageNo = @NextMessageNo + 1
 
        --add main message 100093 = The &1 entered already exists. 
        EXEC AddObjectMainMessageSp 'IX_ILC_country_iso_country_code', 17, 100093, 16, 'ISO Country Code UQ violation', 0 
 
        --add the substitution text
        EXEC AddApplicationMessageSp @NextMessageNo, 'ISO Country Code', N'1033'
 
        --add substitution text to main message
        EXEC AddObjectBuildMessageSp 'IX_ILC_country_iso_country_code', 17, 1, @NextMessageNo
END

Comments