这个“ALTER TABLE”有什么问题?命令?
这是命令;
ALTER TABLE product
ADD CONSTRAINT prod_cust_fk
FOREIGN KEY (cust_id) REFERENCES customer (cust_id) ENABLE;
ALTER TABLE product
ADD CONSTRAINT prod_sto_fk
FOREIGN KEY (sto_id) REFERENCES bakery (sto_id) ENABLE;
ALTER TABLE product
ADD CONSTRAINT prod_sup_fk
FOREIGN KEY (sup_id) REFERENCES supplier (sup_id) ENABLE;
CREATE INDEX prod_cust_ix ON product (cust_id);
CREATE INDEX prod_sto_ix ON product (sto_id);
CREATE INDEX prod_sup_ix ON product (sup_id);
结果:
“ORA-01735: 无效的 ALTER TABLE 选项
ORA-06512:位于“SYS.WWV_DBMS_SQL_APEX_210200”,第 673 行ORA-06512:位于“SYS.DBMS_SYS_SQL”,第 1658 行
ORA-06512: 在“SYS.WWV_DBMS_SQL_APEX_210200”,第 659 行
ORA-06512:位于“APEX_210200.WWV_FLOW_DYNAMIC_EXEC”,第 1829 行参考面包店(sto_id)启用;
更改表产品添加约束 prod_sup_fk 外键 (sup_id) 参考供应商 (sup_id) 启用;
在产品 (cust_id) 上创建索引 prod_cust_ix;
在产品 (sto_id) 上创建索引 prod_sto_ix;"
表product
CREATE TABLE product
(
prod_id VARCHAR2(10) CONSTRAINT prod_id_nn NOT NULL ENABLE,
prod_price NUMBER(3, 2) CONSTRAINT prod_price_nn NOT NULL ENABLE,
prod_avail VARCHAR2(20) CONSTRAINT prod_avail_nn NOT NULL ENABLE,
prod_mdate DATE CONSTRAINT prod_mdate_nn NOT NULL ENABLE,
prod_edate DATE CONSTRAINT prod_edate_nn NOT NULL ENABLE,
cust_id NUMBER(4, 0),
sto_id VARCHAR(8) CONSTRAINT sto_id_nn NOT NULL ENABLE,
sup_id VARCHAR(10),
CONSTRAINT prod_id_pk PRIMARY KEY (prod_id) USING INDEX ENABLE,
CONSTRAINT prod_date_interval CHECK (prod_edate > prod_mdate) ENABLE
表customer
CREATE TABLE customer
(
cust_id NUMBER(4,0) CONSTRAINT cust_id_nn NOT NULL ENABLE,
cust_name VARCHAR2(500),
cust_phone NUMBER(20),
cust_add VARCHAR2(1000),
cust_email VARCHAR2(400),
CONSTRAINT customer_cust_id_pk PRIMARY KEY (cust_id) ENABLE
);
表bakery
CREATE TABLE bakery
(
sto_id VARCHAR(8),
sto_phone NUMBER(20) CONSTRAINT sto_phone_nn NOT NULL ENABLE,
sto_add VARCHAR2(500) CONSTRAINT sto_add_nn NOT NULL ENABLE,
sto_email VARCHAR2(400) CONSTRAINT sto_email_nn NOT NULL ENABLE,
CONSTRAINT sto_id_pk PRIMARY KEY (sto_id) USING INDEX ENABLE
);
表supplier
CREATE TABLE supplier
(
sup_id VARCHAR2(10) CONSTRAINT sup_id_nn NOT NULL ENABLE,
sup_name VARCHAR2(500) CONSTRAINT sup_name_NN NOT NULL ENABLE,
sup_add VARCHAR2(500) CONSTRAINT sup_add_nn NOT NULL ENABLE,
CONSTRAINT sup_id_pk PRIMARY KEY (sup_id) USING INDEX ENABLE
);
我使用的是Oracle APEX 21.2.0
Here is the command;
ALTER TABLE product
ADD CONSTRAINT prod_cust_fk
FOREIGN KEY (cust_id) REFERENCES customer (cust_id) ENABLE;
ALTER TABLE product
ADD CONSTRAINT prod_sto_fk
FOREIGN KEY (sto_id) REFERENCES bakery (sto_id) ENABLE;
ALTER TABLE product
ADD CONSTRAINT prod_sup_fk
FOREIGN KEY (sup_id) REFERENCES supplier (sup_id) ENABLE;
CREATE INDEX prod_cust_ix ON product (cust_id);
CREATE INDEX prod_sto_ix ON product (sto_id);
CREATE INDEX prod_sup_ix ON product (sup_id);
The result:
"ORA-01735: invalid ALTER TABLE option
ORA-06512: at "SYS.WWV_DBMS_SQL_APEX_210200", line 673ORA-06512: at "SYS.DBMS_SYS_SQL", line 1658
ORA-06512: at "SYS.WWV_DBMS_SQL_APEX_210200", line 659
ORA-06512: at "APEX_210200.WWV_FLOW_DYNAMIC_EXEC", line 1829REFERENCES bakery (sto_id) ENABLE;
ALTER TABLE product ADD CONSTRAINT prod_sup_fk FOREIGN KEY (sup_id)
REFERENCES supplier (sup_id) ENABLE;CREATE INDEX prod_cust_ix ON product (cust_id);
CREATE INDEX prod_sto_ix ON product (sto_id);"
The table product
CREATE TABLE product
(
prod_id VARCHAR2(10) CONSTRAINT prod_id_nn NOT NULL ENABLE,
prod_price NUMBER(3, 2) CONSTRAINT prod_price_nn NOT NULL ENABLE,
prod_avail VARCHAR2(20) CONSTRAINT prod_avail_nn NOT NULL ENABLE,
prod_mdate DATE CONSTRAINT prod_mdate_nn NOT NULL ENABLE,
prod_edate DATE CONSTRAINT prod_edate_nn NOT NULL ENABLE,
cust_id NUMBER(4, 0),
sto_id VARCHAR(8) CONSTRAINT sto_id_nn NOT NULL ENABLE,
sup_id VARCHAR(10),
CONSTRAINT prod_id_pk PRIMARY KEY (prod_id) USING INDEX ENABLE,
CONSTRAINT prod_date_interval CHECK (prod_edate > prod_mdate) ENABLE
Table customer
CREATE TABLE customer
(
cust_id NUMBER(4,0) CONSTRAINT cust_id_nn NOT NULL ENABLE,
cust_name VARCHAR2(500),
cust_phone NUMBER(20),
cust_add VARCHAR2(1000),
cust_email VARCHAR2(400),
CONSTRAINT customer_cust_id_pk PRIMARY KEY (cust_id) ENABLE
);
Table bakery
CREATE TABLE bakery
(
sto_id VARCHAR(8),
sto_phone NUMBER(20) CONSTRAINT sto_phone_nn NOT NULL ENABLE,
sto_add VARCHAR2(500) CONSTRAINT sto_add_nn NOT NULL ENABLE,
sto_email VARCHAR2(400) CONSTRAINT sto_email_nn NOT NULL ENABLE,
CONSTRAINT sto_id_pk PRIMARY KEY (sto_id) USING INDEX ENABLE
);
Table supplier
CREATE TABLE supplier
(
sup_id VARCHAR2(10) CONSTRAINT sup_id_nn NOT NULL ENABLE,
sup_name VARCHAR2(500) CONSTRAINT sup_name_NN NOT NULL ENABLE,
sup_add VARCHAR2(500) CONSTRAINT sup_add_nn NOT NULL ENABLE,
CONSTRAINT sup_id_pk PRIMARY KEY (sup_id) USING INDEX ENABLE
);
I'm using Oracle APEX 21.2.0
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论