Create a role table
CREATE TABLE Nbctxp. Tbl_nbc_nonbankrole (
ID BIGINT not NULL,
ROLENAME VARCHAR (50),
Createtime TIMESTAMP,
UpdateTime TIMESTAMP,
CONSTRAINT p_id PRIMARY KEY (ID)
);
CREATE INDEX SQL150130091455900 on NBCTXP. Tbl_nbc_nonbankrole (ID);
Let the primary key increment by 1
Alter table Nbctxp. Tbl_nbc_nonbankrole ALTER column ID set generated always as identity (start with 1,increment by 1)
Create an intermediate table of role tables and user tables
CREATE TABLE Nbctxp. Tbl_nbc_nonbankur (
USERID BIGINT not NULL,
Roleid BIGINT not NULL,
CONSTRAINT pk_ur PRIMARY KEY (Userid,roleid),
CONSTRAINT fk_uid FOREIGN KEY (USERID) REFERENCES nbctxp. Tbl_nbc_nonbankuser (ID),
CONSTRAINT Fk_rid FOREIGN KEY (Roleid) REFERENCES nbctxp. Tbl_nbc_nonbankrole (ID)
);
CREATE INDEX Pk_ur on NBCTXP. Tbl_nbc_nonbankur (Userid,roleid);
DB2 database creates a table and adds a primary key to the table and creates an SQL statement for the performance and intermediate table