.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!



Home >> Interview Question >> Sql Server >> Post New Question Subscribe to Interview Questions

Database: What is the difference between primary key and foreign key?

Posted By :shankey     Posted Date :August 01, 2011    Points :40   Category :Sql Server 

PK will enforce entity integrity whereas FK will enforce referential integrity.


You can also find related Interview Question to Database: What is the difference between primary key and foreign key?  below: 

what is the difference between primary key and foreign key?

  
A primary key is a column which uniquely identifies the
records in a table. In a broad sense, a primary key is the
mixture of a unique key and an index: A collumn with a primary
key is indexed to deliver a faster query, and doesn't allow
duplicate values to ensure specific data.

A foreign key is a column (the child collumn) in a table which
has a corresponding relationship and a dependency on another
collumn (the parent collumn) that is usually in a different
table. Parent collumns can have multiple child collumns, but a
child collumn can only have one parent collumn.

Primary key does't allow null value
while foreign key allow null value
(More...)

Database: Define primary key and foreign key?

  
Primary key is use to uniquely identify each row they are unique and cannot be null where as foreign key are use to ensure data integrity and relationship between tables. (More...)

What are primary keys and foreign keys?

  
Primary keys are the unique identifiers for each row. They must contain unique values and cannot be null. Due to their importance in relational databases, Primary keys are the most fundamental of all keys and constraints. A table can have only one Primary key.
Foreign keys are both a method of ensuring data integrity and a manifestation of the relationship between tables.


Shashi Ray (More...)

What is the difference between unique and primary keys in Oracle SQL?

  
A table can have only one PRIMARY KEY whereas there can be any number of UNIQUE keys. The columns that compose PrimaryKey are automatically defined as NOT NULL, whereas a column that compose a UNIQUE is not automatically defined to be mandatory must also specify the column is NOT NULL.
(More...)

What's the difference between a primary key and a unique key?

  
Both primary key and unique enforce uniqueness of the column on which they are defined. But by default primary key creates a clustered index on the column, where are unique creates a nonclustered index by default. Another major difference is that, primary key doesn't allow NULLs, but unique key allows one NULL only. (More...)

What's the difference between a primary key and a unique key?

  
Both primary key and unique key enforces uniqueness of the column on which they are defined. But by default primary key creates a clustered index on the column, where are unique creates a nonclustered index by default. Another major difference is that, primary key doesn't allow NULLs, but unique key allows one NULL only (More...)

What are primary keys and foreign keys?

  
Primary keys are the unique identifiers for each row. They must contain unique values and cannot be null. Due to their importance in relational databases, Primary keys are the most fundamental of all keys and constraints. A table can have only one Primary key.
Foreign keys are both a method of ensuring data integrity and a manifestation of the relationship between tables. (More...)

Difference between primary and unique key constraints

  
Unique Key Constraints
The column values should retain uniqueness.
It allows null values in the column.
It will create non-clustered index by default.
Any number of unique constraints can be added to a table.


Primary Key Constraints
Primary key will create column data uniqueness in the table.
It will not allow Null values.
By default Primary key will create clustered index.
Only one Primary key can be created for a table.
(More...)

Database: Difference between stored procedure and trigger?

  
.Stored procedure are called explicitly where as trigger are called implicitly.
.Stored procedure are not attached to specific table where as triggers are attached to specific table.
.Stored procedure are called by invoking a CALL to it where this does not applies in case of trigger.


(More...)

Database: Difference between Function and stored procedure?

  

Function can be used in sql statements anywhere in where/select/having etc. where as stored procedure cannot be.
(More...)

Difference between Primary key and unique key?

  
Primary key dont allow null values where as Unique key allow null value.
Primary key create clustured index on column whereas unique key create non-clustured index. (More...)

Database:Difference between delete and truncated?

  
Tuncate is faster and do few system and transcation log resource.
(More...)

Database: How many primary key constraints can be created for one table?

  
Only one primary key constraints can be created for one table. (More...)

Quick Links For Interview Questions Categories:
ASP.Net Windows Application   .NET Framework   C#   VB.Net   ADO.Net  
Sql Server   SharePoint   Silverlight   OOPs   JQuery   JavaScript/VBScript
Biztalk Patten/Practices .IIS WCF WPF WWF
Networking Aptitude Others   All      

Find questions, FAQ's and their answers related to .NET, C#, Vb.Net, Sql Server and many more.

 
Now you can find lots of .NET, C#, Vb.Net, SQL Server,Windows, ASP.Net related Questions and their Answers here at www.dotnetspark.com. Our aim is to help you pass your certification Exams (MCP, MCSD, MCAD etc.,) with flying scores and get good name in your company.

So, Start looking our Interview Question section daily and improve your .NET Skills. You can also help others by posting Interview Questions and their Answers in this section.


Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend