UPDATE TBDD_BASECONFIG SET DB_VERSION = '1.9.1.0'
GO
CREATE TABLE TBDD_USER_REPRESENTATION (
	GUID				INTEGER			NOT NULL	IDENTITY(1,1),
	USER_ID				INTEGER			NOT NULL,
	REPR_GROUP			INTEGER			NOT NULL,
	RIGHT_GROUP			INTEGER			NOT NULL,
	ADDED_WHO			VARCHAR(50)		NOT NULL	DEFAULT 'DEFAULT',
	ADDED_WHEN			DATETIME 					DEFAULT GETDATE(),
	CHANGED_WHO			VARCHAR(50),
	CHANGED_WHEN		DATETIME,
	CONSTRAINT			PK_TBDD_USER_REPRESENTATION PRIMARY KEY (GUID),
	CONSTRAINT			FK_TBDD_USER_REPRESENTATION_USER_ID FOREIGN KEY (USER_ID)  REFERENCES  TBDD_USER (GUID),
	CONSTRAINT			FK_TBDD_USER_REPRESENTATION_REPR_GROUP FOREIGN KEY (REPR_GROUP)  REFERENCES  TBDD_GROUPS (GUID),
	CONSTRAINT			FK_TBDD_USER_REPRESENTATION_RIGHT_GROUP FOREIGN KEY (RIGHT_GROUP)  REFERENCES  TBDD_GROUPS (GUID)
)
GO
CREATE TRIGGER TBDD_USER_REPRESENTATION_AFT_UPD ON TBDD_USER_REPRESENTATION
FOR UPDATE
AS
  UPDATE TBDD_USER_REPRESENTATION SET CHANGED_WHEN = GETDATE()
  FROM INSERTED
  WHERE TBDD_USER_REPRESENTATION.GUID = INSERTED.GUID
GO