简体   繁体   English

SQL 外键 - 表或视图不存在

[英]SQL Foreign key -Table or view does not exist

Create Table Address (
HouseNo NUMBER,
Street VARCHAR2(30),
constraint address_id_nn PRIMARY KEY(HouseNo,Street,City),
city VARCHAR2(20) REFERENCES City(City),
zip NUMBER(6) CHECK(zip >=0),
state varchar2(25));

While running the query i get the message "table or view does not exist".Can any one tell why do we get this?运行查询时,我收到消息“表或视图不存在”。有人能告诉我们为什么会这样吗?

Remove the part REFERENCES City(City) and it should work.删除REFERENCES City(City)部分,它应该可以工作。

The REFERENCES clause always refers to a different table than the one you are currently creating. REFERENCES子句始终引用与您当前创建的表不同的表。 See the first example in https://www.w3schools.com/sql/sql_foreignkey.asp请参阅https://www.w3schools.com/sql/sql_foreignkey.asp中的第一个示例

If the table City really exists, so you must have necessary Grants, at least SELECT (I think you don't have SELECT grant on this table or view, you can not see it) and REFERENCES (as Stick bit recommand to you).如果表 City 确实存在,那么您必须有必要的 Grants,至少 SELECT(我认为您在此表或视图上没有 SELECT 授予,您看不到它)和 REFERENCES(作为 Stick bit 建议给您)。 To test if the table exist, you can tape in your SQL Developer or SQL*Plus:要测试该表是否存在,您可以在 SQL Developer 或 SQL*Plus 中录制:

SELECT count(*) FROM CITY;

If you have this error message "table or view does not exist", ask your DBA to allowing you the SELECT & REFERENCES (as said by Sticky bit) GRANTS.如果您有此错误消息“表或视图不存在”,请让您的 DBA 允许您使用 SELECT 和参考(如 Sticky bit 所说)授予。 Or prefix City by its owner (or schema) like HR .City to acceed id.或在 City 的所有者(或模式)前加上HR .City 等前缀以获取 ID。

If you don't have any error messages.如果您没有任何错误消息。 So, be sure the table CITY contains the CITY column.因此,请确保表 CITY 包含 CITY 列。 To verify this, tape and execute:要验证这一点,请录制并执行:

DESC city;

This will show you all columns of the City table, and you can see if city Column really exists and its type.这将显示 City 表的所有列,并且您可以查看 city 列是否真的存在及其类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM