create sequence seq_STOCKTRANSFERUNIQUEITEM start with 1 increment by 1;
      
      /*
      ACTION is CREATE Table STOCKTRANSFERUNIQUEITEM
      */

CREATE TABLE STOCKTRANSFERUNIQUEITEM (
       STOCKTRANSFERUNIQUEITEM_ID NUMBER NOT NULL,
       STOCKTRANSFERHEADER_ID NUMBER NULL,
       STOCKTRANSFERLINE_ID NUMBER NULL,
       UNIQUEITEM_LINK_ID   NUMBER NOT NULL,
       PRIMARY_ID           VARCHAR2(24) NOT NULL,
       ACCEPTED             VARCHAR2(1) DEFAULT 'N' NOT NULL
                                   CONSTRAINT YN_ValidationNew96
                                          CHECK (ACCEPTED IN ('Y', 'N')),
       DATEPROCESSED        DATE NULL,
       PROCESSINGUSER_ID    NUMBER NULL,
       SYSTEMUSER_ID        NUMBER NOT NULL,
       TIMESTAMP            DATE NOT NULL
);

COMMENT ON COLUMN STOCKTRANSFERUNIQUEITEM.UNIQUEITEM_LINK_ID IS 'UniqueItem_Link_ID = UniqueItem_ID or
UniqueItem_Link_ID = RaggedItem_ID';
CREATE UNIQUE INDEX XAK1STOCKTRANSFERUNIQUEITEM ON STOCKTRANSFERUNIQUEITEM
(
       STOCKTRANSFERHEADER_ID         ,
       STOCKTRANSFERLINE_ID           ,
       UNIQUEITEM_LINK_ID             
);

CREATE UNIQUE INDEX XAK2STOCKTRANSFERUNIQUEITEM ON STOCKTRANSFERUNIQUEITEM
(
       STOCKTRANSFERHEADER_ID         ,
       PRIMARY_ID            
);

CREATE INDEX XIF1STOCKTRANSFERUNIQUEITEM ON STOCKTRANSFERUNIQUEITEM
(
       STOCKTRANSFERHEADER_ID         ASC
);

CREATE INDEX XIF2STOCKTRANSFERUNIQUEITEM ON STOCKTRANSFERUNIQUEITEM
(
       STOCKTRANSFERLINE_ID           ASC
);

CREATE INDEX XIF3STOCKTRANSFERUNIQUEITEM ON STOCKTRANSFERUNIQUEITEM
(
       UNIQUEITEM_LINK_ID             ASC
);


ALTER TABLE STOCKTRANSFERUNIQUEITEM
       ADD  ( CONSTRAINT XPKSTOCKTRANSFERUNIQUEITEM PRIMARY KEY (
              STOCKTRANSFERUNIQUEITEM_ID) ) ;


ALTER TABLE STOCKTRANSFERUNIQUEITEM
       ADD  ( CONSTRAINT STOCKTRANSFERUNIQUEITEM_UNIQUE
              FOREIGN KEY (UNIQUEITEM_LINK_ID)
                             REFERENCES UNIQUEITEM_LINK ) ;


ALTER TABLE STOCKTRANSFERUNIQUEITEM
       ADD  ( CONSTRAINT STOCKTRANSFERUNIQUEITEM_STOCKT
              FOREIGN KEY (STOCKTRANSFERLINE_ID)
                             REFERENCES STOCKTRANSFERLINE ) ;


ALTER TABLE STOCKTRANSFERUNIQUEITEM
       ADD  ( CONSTRAINT STOCKTRANSFERUNIQUEITEM_STOCKH
              FOREIGN KEY (STOCKTRANSFERHEADER_ID)
                             REFERENCES STOCKTRANSFERHEADER ) ;



