
    create table USERMODULE (
        [UUID] uniqueidentifier not null,
        [MODULE] varchar(16),
        [USER_ID] varchar(20),
        [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),
        [AREA] numeric(5,0),
        [LOAD_AUTOMATIC] numeric(5,0),
        [SHOW_IN_FURTHER] numeric(5,0),
        [PARENT_MODULE] varchar(16)
    );

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

    alter table USERMODULE with nocheck
        add constraint FKUSERMODULEID405
        foreign key ([MODULE])
        references DT405
        on delete no action;

    CREATE TRIGGER UFKUSERMODULEID405 ON DT405
        FOR DELETE
        AS
        BEGIN
            DELETE t
            FROM DELETED d
                INNER JOIN USERMODULE t ON d.DI000123 = t.MODULE
        END;

    alter table USERMODULE with check check constraint FKUSERMODULEID405;


    alter table USERMODULE with nocheck
        add constraint FKUSERMODULEID511
        foreign key ([USER_ID])
        references DT511
        on delete no action;

    CREATE TRIGGER UFKUSERMODULEID511 ON DT511
        FOR DELETE
        AS
        BEGIN
            DELETE t
            FROM DELETED d
                INNER JOIN USERMODULE t ON d.DI010323 = t.USER_ID
        END;

    alter table USERMODULE with check check constraint FKUSERMODULEID511;


    create index IDX_USERMODULEID405 on USERMODULE ([MODULE]);


    create index IDX_USERMODULEID511 on USERMODULE ([USER_ID]);


    alter table USERMODULE
        add constraint DT170UUID_DEFAULT DEFAULT newid() FOR [UUID];


    alter table USERMODULE
        add constraint DT170UUID_NOT_NULL check([UUID] is not null);


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


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


    alter table USERMODULE
        add constraint DT170DI064224_DEFAULT DEFAULT 0 FOR [OS_RWDU];


    alter table USERMODULE
        add constraint DT170DI064225_DEFAULT DEFAULT 0 FOR [OS_OWNER];


    alter table USERMODULE
        add constraint DT170DI064226_DEFAULT DEFAULT 0 FOR [OS_GROUP];


    alter table USERMODULE
        add constraint DT170DI064227_DEFAULT DEFAULT 0 FOR [OS_ANY];


    alter table USERMODULE
        add constraint DT170DI064228_DEFAULT DEFAULT 0 FOR [AREA];


    alter table USERMODULE
        add constraint DT170DI064229_DEFAULT DEFAULT 0 FOR [LOAD_AUTOMATIC];


    alter table USERMODULE
        add constraint DT170DI064230_DEFAULT DEFAULT 0 FOR [SHOW_IN_FURTHER];

