我对数据库和Oracle比较陌生,我试图为涉及2个表的项目创建一个数据库; Klant(客户)和Account_。这两个人都将PK作为外键。由于这种情况,我必须在创建表之后创建外键,从而产生此
DROP TABLE KLANT CASCADE CONSTRAINTS;
DROP TABLE ACCOUNT_ CASCADE CONSTRAINTS;
CREATE TABLE KLANT
(
"KlandId" INT PRIMARY KEY,
"AccountId" INT,
"Voornaam" VARCHAR2(64)NOT NULL,
"Achternaam" VARCHAR2(64) NOT NULL,
"GENDER" CHAR(1) DEFAULT 'M' CHECK (UPPER(GENDER) in ('M','F')),
"Tussenvoegsels" VARCHAR2(16),
"EmailAdres" VARCHAR2(64),
"Land" VARCHAR2(64) DEFAULT 'Nederland',
"Stad" VARCHAR2(64),
"Adres" VARCHAR2(64),
"Toevoeging" CHAR(1));
CREATE TABLE Account_
(
"AccountId" INT PRIMARY KEY,
"KlantId_" INT,
"GebruikersNaam" VARCHAR2(64)UNIQUE NOT NULL,
"Wachtwoord" VARCHAR2(64)
);
ALTER TABLE KLANT
ADD CONSTRAINT fk_accountId FOREIGN KEY (AccountId) REFERENCES "Account_"(AccountId);
ALTER TABLE Account_
ADD CONSTRAINT fk_klantId FOREIGN KEY (KlantId_) REFERENCES "Klant"(KlantId);
这让我产生了以下错误:
Error starting at line : 39 in command -
ALTER TABLE KLANT
ADD CONSTRAINT fk_accountId FOREIGN KEY (AccountId) REFERENCES "Account_"(AccountId)
Error report -
SQL Error: ORA-00904: "ACCOUNTID": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
抱歉所有的荷兰语:(
我的问题是:我在哪里陷入困境,因为它可能是一种荒谬的愚蠢行为。
答案 0 :(得分:0)
引用AccountId。在Oracle中,对象通常是大写的。当您使用AccountId而不引用它时,Oracle将寻找ACCOUNTID。
答案 1 :(得分:0)
ALTER TABLE KLANT
ADD CONSTRAINT fk_accountId FOREIGN KEY ("AccountId") REFERENCES Account_("AccountId");
Account_ Table的名称不应该是双引号。另一张桌也一样。