【问题标题】:Writing a script that implements the following design编写实现以下设计的脚本
【发布时间】:2020-11-14 17:46:02
【问题描述】:

我写了这段代码,但我不知道为什么会出错

错误报告 - ORA-00903: 无效的表名

Create table downloads
(
 download_id   int Primary Key NOT NULL,
 User_id       int,
 download_date date,
 filename      Varchar(20),
 product_id    int,
 CONSTRAINT fk_column FOREIGN KEY (USER_id) REFERENCES user (user_id),
 FOREIGN KEY (product_id) REFERENCES products(product_id)
);

【问题讨论】:

  • user 不能用作表名,除非引用(例如 "user")作为保留关键字。顺便说一句,在Primary Key 旁边使用NOT NULL 是多余的。
  • 另外,请注意在 Oracle 中引用表、列或其他对象名称通常被认为是一种不好的做法,因为在引用该对象时您必须始终使用引号。首先避免保留关键字要好得多。

标签: oracle ddl


【解决方案1】:

您不能创建名为“user”的表。 请删除“CONSTRAINT fk_column FOREIGN KEY (USER_id) REFERENCES user (user_id)”行 并使用以下内容:

Create table downloads2
(
 download_id   int Primary Key NOT NULL,
 User_id       int,
 download_date date,
 filename      Varchar(20),
 product_id    int,
 FOREIGN KEY (product_id) REFERENCES departments(department_id)
);

【讨论】:

    猜你喜欢
    • 2020-12-04
    • 1970-01-01
    • 2018-08-12
    • 2010-09-05
    • 1970-01-01
    • 2011-08-14
    • 1970-01-01
    • 2020-12-06
    • 1970-01-01
    相关资源
    最近更新 更多