
    create table STAKEHOLDERPORTFOLIO (
        [UUID] uniqueidentifier not null,
        [ASSIGNMENT_ID] numeric(10,0) not null,
        [MEMBER_ID] varchar(20),
        [PORTFOLIO_ID] varchar(18) not null,
        [OS_CREATED_ON] datetime2,
        [OS_MODIFIED_ON] datetime2,
        [OS_RWDU] numeric(5,0),
        [OS_CREATED_BY] varchar(20),
        [OS_MODIFIED_BY] varchar(20),
        [OS_LICENSE] varchar(4),
        [OS_OPC] varchar(8),
        [OS_OWNER] numeric(5,0),
        [OS_GROUP] numeric(5,0),
        [OS_ANY] numeric(5,0),
        [ROLE] numeric(10,0),
        [COMMENT] varchar(max),
        [MOD_ACCESS] numeric(5,0),
        [ALLOCATOR] numeric(10,0),
        [CATEGORY] numeric(10,0),
        [MAIN_EXECUTIVE] numeric(5,0)
    );

    IF NOT EXISTS (SELECT * FROM SYS.INDEXES
       WHERE IS_PRIMARY_KEY = 1 AND OBJECT_ID IN
             (SELECT OBJECT_ID FROM SYS.TABLES WHERE NAME = 'STAKEHOLDERPORTFOLIO'))
       alter table STAKEHOLDERPORTFOLIO add constraint PID533DT533 primary key ([ASSIGNMENT_ID]);


    alter table STAKEHOLDERPORTFOLIO with nocheck
        add constraint FKSTAKEHOLDERPORTFOLIOID870
        foreign key ([PORTFOLIO_ID])
        references DT870
        on delete no action;


    CREATE TRIGGER UFKSTAKEHOLDERPORTFOLIOID870 ON DT870
        FOR DELETE
        AS
        BEGIN
            DELETE t
            FROM DELETED d
                INNER JOIN STAKEHOLDERPORTFOLIO t ON d.DI028667 = t.PORTFOLIO_ID
        END;

    alter table STAKEHOLDERPORTFOLIO with check check constraint FKSTAKEHOLDERPORTFOLIOID870;


    alter table STAKEHOLDERPORTFOLIO with nocheck
        add constraint FKSTAKEHOLDERPORTFOLIOID525
        foreign key ([MEMBER_ID])
        references DT525
        on delete no action;

    CREATE TRIGGER UFKSTAKEHOLDERPORTFOLIOID525 ON DT525
        FOR DELETE
        AS
        BEGIN
            DELETE t
            FROM DELETED d
                INNER JOIN STAKEHOLDERPORTFOLIO t ON d.DI026520 = t.MEMBER_ID
        END;

    alter table STAKEHOLDERPORTFOLIO with check check constraint FKSTAKEHOLDERPORTFOLIOID525;


    create index IDX_ITEXT_DT533ROLE on STAKEHOLDERPORTFOLIO ([ROLE]);


    create index IDX_STAKEHOLDERPORTFOLIOID870 on STAKEHOLDERPORTFOLIO ([PORTFOLIO_ID]);


    create index IDX_STAKEHOLDERPORTFOLIOID525 on STAKEHOLDERPORTFOLIO ([MEMBER_ID]);


    alter table STAKEHOLDERPORTFOLIO
        add constraint UUID_UNIQUE_533  unique ([UUID]);


    alter table STAKEHOLDERPORTFOLIO
        add constraint DT533UUID_DEFAULT DEFAULT newid() FOR [UUID];


    alter table STAKEHOLDERPORTFOLIO
        add constraint DT533UUID_NOT_NULL check([UUID] is not null);


    alter table STAKEHOLDERPORTFOLIO
        add constraint DT533DI064440_DEFAULT DEFAULT 0 FOR [ASSIGNMENT_ID];


    alter table STAKEHOLDERPORTFOLIO
        add constraint DT533ASSIGNMENT_ID_NOT_NULL check([ASSIGNMENT_ID] is not null);


    alter table STAKEHOLDERPORTFOLIO
        add constraint DT533MEMBER_ID_NOT_NULL check([MEMBER_ID] is not null);

    alter table STAKEHOLDERPORTFOLIO
        add constraint DT533PORTFOLIO_ID_NOT_NULL check([PORTFOLIO_ID] is not null);

    alter table STAKEHOLDERPORTFOLIO
        add constraint DT533DI064443_DEFAULT DEFAULT CONVERT(datetime2,'01.01.1970',104) FOR [OS_CREATED_ON];


    alter table STAKEHOLDERPORTFOLIO
        add constraint DT533DI064444_DEFAULT DEFAULT CONVERT(datetime2,'01.01.1970',104) FOR [OS_MODIFIED_ON];


    alter table STAKEHOLDERPORTFOLIO
        add constraint DT533DI064445_DEFAULT DEFAULT 0 FOR [OS_RWDU];


    alter table STAKEHOLDERPORTFOLIO
        add constraint DT533DI064450_DEFAULT DEFAULT 0 FOR [OS_OWNER];


    alter table STAKEHOLDERPORTFOLIO
        add constraint DT533DI064451_DEFAULT DEFAULT 0 FOR [OS_GROUP];


    alter table STAKEHOLDERPORTFOLIO
        add constraint DT533DI064452_DEFAULT DEFAULT 0 FOR [OS_ANY];


    alter table STAKEHOLDERPORTFOLIO
        add constraint DT533DI064456_DEFAULT DEFAULT 0 FOR [MOD_ACCESS];


    alter table STAKEHOLDERPORTFOLIO
        add constraint DT533DI064457_DEFAULT DEFAULT 0 FOR [ALLOCATOR];


    alter table STAKEHOLDERPORTFOLIO
        add constraint DT533DI064458_DEFAULT DEFAULT 0 FOR [CATEGORY];


    alter table STAKEHOLDERPORTFOLIO
        add constraint DT533DI064459_DEFAULT DEFAULT 0 FOR [MAIN_EXECUTIVE];

