create table DT532 (
    [UUID] uniqueidentifier not null,
    [ASSIGNMENT_ID_ID] numeric(10,0),
    [MEMBER_ID] varchar(20),
    [PR_ID] varchar(18),
    [REPORT_ID] varchar(10),
    [CREATED_ON] datetime2,
    [MODIFIED_ON] datetime2,
    [RWDU] numeric(5,0),
    [CREATED_BY] varchar(20),
    [MODIFIED_BY] varchar(20),
    [OWN_LIC] varchar(4),
    [OPC] varchar(8),
    [OWNER] numeric(5,0),
    [GROUP] numeric(5,0),
    [ANY] numeric(5,0),
    [ROLE] numeric(10,0),
    [MAX_PER_DAY] numeric(5,0),
    [WITHOUT_COST_CALC] numeric(5,0),
    [COMMENT] varchar(max),
    [MOD_ACCESS] numeric(5,0),
    [WATCHER] numeric(5,0),
    [NAME_2] numeric(10,0),
    [ALLOCATOR] numeric(10,0),
    [CATEGORY] numeric(10,0),
    [MAIN_EXECUTIVE] numeric(5,0),
    [TDI_SUB_PROJECT_VIEW] varchar(max)
);

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

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

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

alter table DT532 with check check constraint FKDT532ID525;

alter table DT532 with nocheck
    add constraint FKDT532ID461
    foreign key ([PR_ID])
    references DT461
    on delete no action;

CREATE TRIGGER UFKDT532ID461 ON DT461
    FOR DELETE
    AS
    BEGIN
        DELETE t
        FROM DELETED d
            INNER JOIN DT532 t ON d.DI001001 = t.PR_ID
    END;

alter table DT532 with check check constraint FKDT532ID461;

alter table DT532 with nocheck
    add constraint FKDT532ID823
    foreign key ([PR_ID], [REPORT_ID])
    references DT823
    on delete no action;

CREATE TRIGGER UFKDT532ID823 ON DT823
    FOR DELETE
    AS
    BEGIN
        DELETE t
        FROM DELETED d
            INNER JOIN DT532 t ON d.DI008413 = t.PR_ID
                              AND d.DI008416 = t.REPORT_ID
    END;

alter table DT532 with check check constraint FKDT532ID823;

create index IDX_ITEXT_DT532ROLE on DT532 ([ROLE]);

create index IDX_ITEXT_DT532NAME_2 on DT532 ([NAME_2]);

create index IDX_DT532ID525 on DT532 ([MEMBER_ID]);

create index IDX_DT532ID461 on DT532 ([PR_ID]);

create index IDX_DT532ID823 on DT532 ([PR_ID], [REPORT_ID]);

alter table DT532
    add constraint DT532UUID_DEFAULT DEFAULT newid() FOR [UUID];

alter table DT532
    add constraint DT532UUID_NOT_NULL check([UUID] is not null);

alter table DT532
    add constraint DT532DI063932_DEFAULT DEFAULT 0 FOR [ASSIGNMENT_ID_ID];

alter table DT532
    add constraint DT532ASSIGNMENT_ID_ID_NOT_NULL check([ASSIGNMENT_ID_ID] is not null);

alter table DT532
    add constraint DT532MEMBER_ID_NOT_NULL check([MEMBER_ID] is not null);

alter table DT532
    add constraint DT532REPORT_ID_NOT_NULL check([REPORT_ID] is not null);

alter table DT532
    add constraint DT532DI063929_DEFAULT DEFAULT CONVERT(datetime2,'01.01.1970',104) FOR [CREATED_ON];

alter table DT532
    add constraint DT532DI063928_DEFAULT DEFAULT CONVERT(datetime2,'01.01.1970',104) FOR [MODIFIED_ON];

alter table DT532
    add constraint DT532DI063927_DEFAULT DEFAULT 0 FOR [RWDU];

alter table DT532
    add constraint DT532DI063922_DEFAULT DEFAULT 0 FOR [OWNER];

alter table DT532
    add constraint DT532DI063921_DEFAULT DEFAULT 0 FOR [GROUP];

alter table DT532
    add constraint DT532DI063920_DEFAULT DEFAULT 0 FOR [ANY];

alter table DT532
    add constraint DT532DI063918_DEFAULT DEFAULT 0 FOR [MAX_PER_DAY];

alter table DT532
    add constraint DT532DI063917_DEFAULT DEFAULT 0 FOR [WITHOUT_COST_CALC];

alter table DT532
    add constraint DT532DI063915_DEFAULT DEFAULT 0 FOR [MOD_ACCESS];

alter table DT532
    add constraint DT532DI063914_DEFAULT DEFAULT 0 FOR [WATCHER];

alter table DT532
    add constraint DT532DI063912_DEFAULT DEFAULT 0 FOR [ALLOCATOR];

alter table DT532
    add constraint DT532DI063911_DEFAULT DEFAULT 0 FOR [CATEGORY];

alter table DT532
    add constraint DT532DI063910_DEFAULT DEFAULT 0 FOR [MAIN_EXECUTIVE];
