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


Top 5 Contributors of the Month
david stephan

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

What are primary keys and foreign keys?

Posted By :Dhivakaran     Posted Date :October 25, 2010    Points :10   Category :Sql Server 
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.

You can also find related Interview Question to What are primary keys and foreign keys?  below: 

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 Are Primary 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. (More...)

What Are Foreign Keys?

  
Foreign keys are both a method of ensuring data integrity and a manifestation of the relationship between tables. (More...)

Is it possible to create cookies with keys? Explain using some example.

  
Yes, it is possible to create cookies with keys.
Cookies is a dictionary at the time of initialization, if key is specified with it. (You can determine whether cookie is dictionary or not using HasKeys property. )
For an example:

Response.Cookies("Testcookie")("key1") = "key1"
Response.Cookies("Testcookie")("key2") = "key2"

After this if you make assignment like,
Response.Cookies("Testcookie") = "noKey"
Then," key1" and "key2" of cookie("Testcookie") will be deleted. (More...)

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

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

  

PK will enforce entity integrity whereas FK will enforce referential integrity.
(More...)

what are the ShoutCut Keys worked in the TextBox when Developer Specify ShoutCut Key for TextBox?

  
CTRL +H = Remove Last Character.
CTRL +Z = Select All Charaters/Last Character in TextBox.
CTRL +X = Cut selected Charaters in TextBox.
CTRL +C = Copy Selected Charaters in TextBox.
CTRL +P = Paste Selected Charaters in TextBox. (More...)

What are different types of SQL keys?

  
1.Primary Key
Primary key is a set of one or more fields/columns of a table that uniquely identify a record in database table. It can not accept null, duplicate values. Only one Candidate Key can be Primary Key.

2.Foreign Key
Foreign Key is a field in database table that is Primary key in another table. It can accept multiple null, duplicate values. For more help refer the article Difference between primary key and foreign key.


3.Super Key
Super key is a set of one or more than one keys that can be used to identify a record uniquely in a table.Example : Primary key, Unique key, Alternate key are subset of Super Keys.

4.Candidate Key
A Candidate Key is a set of one or more fields/columns that can identify a record uniquely in a table. There can be multiple Candidate Keys in one table. Each Candidate Key can work as Primary Key.

5.Alternate key
A Alternate key is a key that can be work as a primary key. Basically it is a candidate key that currently is not primary key.


6.Composite/Compound Key
Composite Key is a combination of more than one fields/columns of a table. It can be a Candidate key, Primary key.

7.Unique Key
Uniquekey is a set of one or more fields/columns of a table that uniquely identify a record in database table. It is like Primary key but it can accept only one null value and it can not have duplicate values. (More...)

Can we use Truncate command on a table which is referenced by FOREIGN KEY?

  
No. We cannot use Truncate command on a table with Foreign Key because of referential integrity (More...)

Can we use Truncate command on a table which is referenced by FOREIGN KEY?

  
No. We cannot use Truncate command on a table with Foreign Key because of referential integrity (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