nelsi silaban
nelsi silaban

Reputation: 1

SQL Error: ORA-02270: no matching unique or primary key for this column-list [ask]

Is it possible to make a column not primary key, to be foreign key in other table? for example :

-- for master table

create table identity(
 id int not null,
 name_identity varchar2(100),
 primary key(id)
);

--for foreign key

create table class(
 class_id int,
 name_identity varchar2(100),
 primary key(class_id),
 foreign key(name_identity) references identity(name_identity)
);

Is it possible to make name_identity as foreign key?

Upvotes: 0

Views: 58

Answers (1)

Sanders the Softwarer
Sanders the Softwarer

Reputation: 2496

Foreign key doesn't rely on column, it's rely on unique key instead. Primary key is a special case of unique key so it can be used as well.

In your case you should use something like name_identity varchar2(100) unique and you'll can use it in foreign key after that.

Upvotes: 1

Related Questions