CREATE TABLE APP_USUARIOQRCODE (
	NRUSUARIOAPLICATIVO NUMBER 			NOT NULL,
	NRQRCODELOCALPESQ 	NUMBER 			NOT NULL,
	NRORG             	NUMBER 	        DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
    IDATIVO           	VARCHAR2(1)     DEFAULT 'S'					NOT NULL,
    DTINCLUSAO        	DATE            DEFAULT SYSDATE,
    DTULTATU          	DATE            DEFAULT SYSDATE,
    NRORGINCLUSAO     	NUMBER          DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg')		NULL,
    CDOPERINCLUSAO    	VARCHAR2(12)    DEFAULT '1' 					NULL,
    NRORGULTATU       	NUMBER          DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg')		NULL,
    CDOPERULTATU      	VARCHAR2(12)    DEFAULT '1',
	   CONSTRAINT CKC_IDATIVO_APP_USUARIOQRCODE CHECK (IDATIVO IN ('S', 'N')), 
	   CONSTRAINT PK_APP_USUARIOQRCODE PRIMARY KEY(NRUSUARIOAPLICATIVO, NRQRCODELOCALPESQ)
)
/
ALTER TABLE APP_USUARIOQRCODE
	ADD CONSTRAINT FKPLA01334USRIOQRCODE_USRIOAPP FOREIGN KEY (NRUSUARIOAPLICATIVO)
		REFERENCES APP_USUARIOAPLICATIVO (NRUSUARIOAPLICATIVO) ON DELETE CASCADE
/
CREATE INDEX PLA01334_FK  ON APP_USUARIOQRCODE (NRUSUARIOAPLICATIVO ASC)
/
ALTER TABLE APP_USUARIOQRCODE
	ADD CONSTRAINT FKPLA01335USUARIOQRCODE_QRCODE FOREIGN KEY (NRQRCODELOCALPESQ)
		REFERENCES QRCODELOCALPESQ (NRQRCODELOCALPESQ) ON DELETE CASCADE
/
CREATE INDEX PLA01335_FK  ON APP_USUARIOQRCODE (NRQRCODELOCALPESQ ASC)
/

ALTER TABLE QRCODELOCALPESQ ADD IDEXIBEALERG VARCHAR2(1) NULL
  CONSTRAINT CKC_IDEXIBEALERG CHECK(IDEXIBEALERG IN ('S','N'))
/