Extra column in UserGroups and UserRoles

Release 1.0 - ...

An extra column Code has been added to the tables UserGroups and UserRoles.

The Code column is used to refer to a specific item, thereby removing the dependency on the name or numeric key of the item.

SQL CopyCode image Copy Code
IF NOT EXISTS (SELECT 1 FROM syscolumns WHERE id=OBJECT_ID('UserRoles') AND name='Code')
BEGIN
    PRINT 'Adding column Code to table UserRoles.'
    ALTER TABLE UserRoles
    ADD Code varchar (50) NOT NULL CONSTRAINT DF_UserRoles_Code DEFAULT ('GUID-' + replace(newid(),'-',''))
 
    ALTER TABLE UserRoles ADD CONSTRAINT UN_UserRoles_Code UNIQUE NONCLUSTERED (Code)
END
 
IF NOT EXISTS (SELECT 1 FROM syscolumns WHERE id=OBJECT_ID('UserGroups') AND name='Code')
BEGIN
    PRINT 'Adding column Code to table UserGroups.'
    ALTER TABLE UserGroups
    ADD Code varchar (50) NOT NULL CONSTRAINT DF_UserGroups_Code DEFAULT ('GUID-' + replace(newid(),'-',''))
    ALTER TABLE UserGroups ADD CONSTRAINT UN_UserGroups_Code UNIQUE NONCLUSTERED (Code)
END