Sql Oracle中的嵌套表主键和外键
我试图将主键和外键添加到嵌套表中,很难知道如何添加 这就是我所拥有的Sql Oracle中的嵌套表主键和外键,sql,oracle,foreign-keys,nested-table,Sql,Oracle,Foreign Keys,Nested Table,我试图将主键和外键添加到嵌套表中,很难知道如何添加 这就是我所拥有的 create or replace type profile as object ( id VARCHAR2(10), --- Suppose to be Primary Key userID VARCHAR2(10) --- Suppose to be Foreign Key for user table ); create or replace type profile_nest as table of profile
create or replace type profile as object
(
id VARCHAR2(10), --- Suppose to be Primary Key
userID VARCHAR2(10) --- Suppose to be Foreign Key for user table
);
create or replace type profile_nest as table of profile;
CREATE OR REPLACE TYPE user_t UNDER group_T
(profile profile_nest_ty,);
CREATE TABLE user OF user_t
(id NOT NULL,
PRIMARY KEY (id),
nested table profile store as profile_storage_tbl;
现在的问题是这一部分,尝试使用外键-
alter table profile_storage_tbl add CONSTRAINT fk_userID FOREIGN KEY (userID)
REFERENCES user(id);
给出了这个错误-
*从命令的第3行开始出错:alter table profile\u storage\u tbl添加约束fk\u userID外键(userID) 参考用户(id)
错误报告:
SQL错误:ORA-30730:嵌套表列上不允许引用约束 3073000000-“嵌套表列上不允许引用约束”
*原因:试图在嵌套对象上定义引用约束 表列。
操作:不要在嵌套表列上指定引用约束
或者创建两个单独的表
profile\u storage\u tbl
和user
,在它们之间使用外键或者创建profile\u storage\u tbl
作为用户
表中的嵌套表。两者兼而有之是没有意义的。(事实上,嵌套表对我来说没什么意义,没错,但那是另一回事!)正如异常文本所说,不允许在嵌套表列上创建外键约束(Oracle 11)
这里介绍了一种解决方法:。但不能保证这会在下一个oracle版本中起作用。幕后oracle将创建两个表profile\u storage\u tbl和user,而profile\u storage\u tbl在user上有一个外键。
您可以自己做这件事,使用advatage可以更好地控制关联(也可以到其他表)。您好,谢谢您的回复。我已经将profile_storage_tbl创建为用户表中的嵌套表。问题是,我有另一个表,我需要与profile\u storage\u tbl嵌套表建立关系。所以我需要知道如何添加约束。谢谢。我想问的是,嵌套表中的每一行是否都有主键或唯一标识符?主键约束和唯一约束为“是”。后者可以在链接文章中看到。您可以在此处看到主键的示例: