sql - 甲骨文 : Foreign Key Error : Unknown Command

标签 sql database oracle oracle-sqldeveloper

每次我尝试制作外键或尝试执行 ON DELETE CASCADE

我收到这样的错误:

Error starting at line 9 in command:
CONSTRAINT tp_landlordrole_FK FOREIGN KEY (zillowuseraccountid)
Error report:
Unknown Command

下面是我的代码示例

PROMPT 'Creating Table landlordrole'
CREATE TABLE tp_landlordrole
(
    landlordroleid          NUMBER(20) NOT NULL,
    zillowuseraccountid         NUMBER(20) NOT NULL,
    numberofpropertiesowned     Number(6),
CONSTRAINT tp_landlordrole_PK PRIMARY KEY ( landlordroleid ) ) ; 

CONSTRAINT tp_landlordrole_FK FOREIGN KEY (zillowuseraccountid)
    REFERENCES  tp_zillowuseraccount(zillowuseraccountid) ON DELETE CASCADE  ;

PROMPT Creating Index 'tp_landlordrole_I'
CREATE INDEX tp_landlordrole_I ON tp_landlordrole
( zillowuseraccountid );

PROMPT 'Creating Sequence tp_landlordroleid_seq for the tp_landlordrole table'
CREATE SEQUENCE tp_landlordroleid_seq START WITH 0 MINVALUE 0 NOCACHE;

欢迎提出任何建议!!

最佳答案

我相信你只需要一个alter table语句:

ALTER TABLE tp_landlordrole 
    ADD CONSTRAINT tp_landlordrole_FK
        FOREIGN KEY (zillowuseraccountid) REFERENCES  tp_zillowuseraccount(zillowuseraccountid) ON DELETE CASCADE  ;

但是,您可以直接在表定义中定义外键。

CREATE INDEXCREATE SEQUENCE 不需要ALTER TABLE

关于sql - 甲骨文 : Foreign Key Error : Unknown Command,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49593101/

相关文章:

xml - 将超过 4000 个字符的 XML 插入到 Oracle XMLTYPE 列中

sql - ORA-30483 : window functions are not allowed here

sql - Db2/Oracle-无法去掉空格

sql - WHERE 大于给定日期时间以减少查询行

c# - Sql DataReader 有行但返回空数据

java - 如何为具有可扩展属性的资源编写DAO?

database - 在 Firestore 中查询没有映射键的文档

SQL Server 一天中每小时返回 4 行

mysql - 数据库设计 : Is it okay for a table to have half-related records?

oracle - oracle apex 中的全局跨应用程序页面或其他一些 UI 对象?