--ABS-80586 / ABS-103259
---------------------BIUSERACCESS-------------

CREATE SEQUENCE SEQ_BIUSERACCESS
START WITH 1
INCREMENT BY 1;

CREATE TABLE BIUSERACCESS
(
BIUSERACCESS_ID         NUMBER NOT NULL,
USERNAME                VARCHAR2(20) NOT NULL,
BISYSTEMUSER_ID         NUMBER NULL,
PLANT_ID                NUMBER NULL,
BUSINESSUNIT_ID         NUMBER NULL,
DEPOT_ID                NUMBER NULL,
ROUTE_ID                NUMBER NULL,
REGION_ID               NUMBER NULL,
DIVISION_ID             NUMBER NULL, 
DISTRICT_ID             NUMBER NULL,
CUSTOMER_ID             NUMBER NULL,
SALESAREA_ID            NUMBER NULL,
SYSTEMUSER_ID           NUMBER NOT NULL,
TIMESTAMP               DATE NOT NULL
);

ALTER TABLE BIUSERACCESS ADD CONSTRAINT XPKBIUSERACCESS PRIMARY KEY (BIUSERACCESS_ID);

CREATE UNIQUE INDEX XAK1BIUSERACCESS ON BIUSERACCESS (USERNAME ASC);

CREATE INDEX XIF1BIUSERACCESS ON BIUSERACCESS (BISYSTEMUSER_ID ASC);

ALTER TABLE BIUSERACCESS ADD CONSTRAINT FK_BIUSERACCESS_BISYSUSER_ID FOREIGN KEY (BISYSTEMUSER_ID)
REFERENCES SYSTEMUSER (SYSTEMUSER_ID) ON DELETE CASCADE;