Interviews4 answers
Can You FK(Foreign Key) reference a table with no primary key?
4 Answers
by the use of unique key not null
Mukesh KumarPosted Aug 23, 2017, 4:34 AM EDT
Yes we can create a FK reference a table with no primary key if column is Unique
Exa:
Create Table My_Tab2
(
id int unique,
nam int
)
Create Table My_Tab3
(
iid int constraint Mycons references My_tab2(id),
namo int not null,
)
Rahul PrajapatPosted May 30, 2015, 6:02 AM EDT
It we can create a FK reference a table with no primary key if column is Unique
Exa:
Create Table My_Tab2
(
id int unique,
nam int
)
Create Table My_Tab3
(
iid int constraint Mycons references My_tab2(id),
namo int not null,
)
Pankaj Kumar ChoudharyPosted May 21, 2015, 8:30 AM EDT
yes you can but column must be unique key has created.
see below
create table Test1
(
ID int unique
);
CREATE TABLE IR.test2
(
Test2_Id int,
FOREIGN KEY (Test2_Id) REFERENCES IR.test1(ID)
)
Abrar Ahmad AnsariPosted Mar 10, 2015, 3:24 AM EDT




