4
Reply

Can You FK(Foreign Key) reference a table with no primary key?

Suresh Paldia

Suresh Paldia

14y
4.8k
0
Reply

    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, )

    by the use of unique key not null

    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, )

    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) )