Can Unique key be used as Foreign Key?

Can unique key be used as foreign key? What is the difference between Primary key and unique key?

Questions by Rehan Naqvi

Showing Answers 1 - 30 of 30 Answers

No, as unique allow only one null in a column and there cannot be any duplicate data can be inserted in that column which is associated with unique key and on the other hand foreign key allow the duplicate key.

  Was this answer useful?  Yes

realrenga

  • Jun 25th, 2010
 

Cannot, foreign key constraint only applied at SQL insert and delete times.

For example, assume a one-to-many relationship between the EMPLOYEE and DEPENDENT tables; each employe may have many dependents, yet each dependent belongs to only one employee. The references constraint tells Oracle at insert time that the value in DEPENDENT.emp_num must match the EMPLOYEE.emp_num in the employee row, thereby ensuring that a valid employee exists before the dependent row is added. At SQL delete time, the references constraint can be used to ensure that an employee is not deleted, if rows still exist in the DEPENDENT table.

But Uinque key is used to ensure all column values within the table never contain a duplicate entry.

  Was this answer useful?  Yes

Puneet Bhatia

  • Sep 11th, 2011
 

Yes, Unique key as well as Primary key can be referenced by Foreign key. Tested also.

  Was this answer useful?  Yes

Deepak Khare

  • Jan 22nd, 2012
 

Answer is Yes. You can find details here http://msdn.microsoft.com/en-us/library/ms175464(v=SQL.90).aspx

  Was this answer useful?  Yes

Henil Mewada

  • Oct 6th, 2015
 

Primary key can be only one in table and more than one unique key in one table. Primary key can be never allow null value and unique key can be candidate key.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions