我已经停止了脚本:
CREATE TABLE OfferCar (
ID BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL PRIMARY KEY,
YEAR_CONSTR SMALLINT,
MONTH_CONSTR TINYINT,
NAME VARCHAR(128),
ENGINE VARCHAR(32),
CAPACITY SMALLINT,
MILEAGE INTEGER,
VENDOR VARCHAR(32),
VENDOR_NAME VARCHAR(128),
LOCATION VARCHAR(128),
PRICE NUMERIC,
SUBJECT VARCHAR(64),
NR BIGINT
);
CREATE TABLE CarDailySimpleAudit (
ID BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL PRIMARY KEY,
DATE TIMESTAMP NOT NULL,
CAR_ID BIGINT NOT NULL
);
ALTER TABLE CarDailySimpleAudit
ADD FOREIGN KEY ( CAR_ID )
REFERENCES OfferCar ( ID );
我无法添加FK约束,因为ID具有标识。
否则:首先我可以定义ID,如:
ID BIGINT NOT NULL PRIMARY KEY
然后添加FK约束 - 但之后我无法添加Identity,因为存在FK约束......