Dot Net Tricks
Dot Net Tricks
Category Tutorial Search C# Design Patterns Asp.Net MVC SQL Server Book Training Advertise About Me Contact
SQL Server 2012, 2008 - Tutorial, Article, Archive, Pdf, Handy Tricks, Training, Code Snippets, Reference Manual, T-SQL, PL/SQL, Development, Administration, Performance Tuning, Backup, Recovery, Reporting, Analysis, Security, XML, CLR Objects
1. 2.
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.
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. Example: In below diagram ID, RollNo and EnrollNo are Candidate Keys since all these three fields can be work as Primary Key.
3. 4. 5.
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.
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. Example: In below diagram RollNo and EnrollNo becomes Alternate Keys when we define ID as Primary Key.
Composite Key is a combination of more than one fields/columns of a table. It can be a Candidate key, Primary key.
6.
Unique Key
between
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. For more help refer the articleDifference
key.
7.
Foreign Key
between primary key and 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
Example : We can have a DeptID column in the Employee table which is pointing to DeptID column in a department table where it a primary key. Defined Keys -
1. CREATE TABLE Department 2. ( 3. DeptID int PRIMARY KEY, 4. Name varchar (50) NOT NULL, 5. Address varchar (200) NOT NULL, ) 6. CREATE TABLE Student 7. ( 8. ID int PRIMARY KEY, 9. RollNo varchar(10) NOT NULL, 10. Name varchar(50) NOT NULL, 11. EnrollNo varchar(50) UNIQUE, 12. Address varchar(200) NOT NULL, 13. DeptID int FOREIGN KEY REFERENCES Department(DeptID) 14. )
Note
1. Practically in database, we have only three types of keys Primary Key, Unique Key and Foreign Key. Other types of keys are only concepts of RDBMS that we need to know.
Summary
In this article I try to explain types of keys in Sql Server with example. I hope after reading this article you will be aware of keys in Sql Server. I would like to have feedback from my blog readers. Please post your feedback, question, or comments about this article.
Prev Next
Recommended Articles !!
1. Different
Types of SQL Joins to SQL Server 3. SQL Server Exception Handling by TRYCATCH 4. Different Types of SQL Server Stored Procedures 5. CRUD Operations using Stored Procedures 6. Definition, Use of Group by and Having Clause 7. Basics of SQL Commands 8. Different Types of SQL Server Views 9. SQL Server Exceptions Working 10. SQL Integrity Constraints or Constraints
2. Introduction
Submit
Search Articles
For finding articles enter search terms
Search
Browse By Category
.Net Framework6 Ado.Net6
Ajax2 Asp.Net14
JQuery4 Knockout5
LINQ6 MVC44
Nhibernate1 OOPS6
SVN1 TFS3
WPF4
Recent Articles
Passing multiple complex type parameter to Web API A Deep Dive into C# Abstract Class A Deep Dive into C# Interface Difference Between Finalize and Dispose Method
Understanding Detailed Architecture of ASP.NET 4.5 Difference Between Generalization & Specialization Understanding Inheritance and Types of Inheritance Understanding Relationship Between CTS and CLS Different Types of JIT Complier Understanding .Net Framework 4.5 Architecture
Popular Articles
Undestanding Cloud Computing and Windows Azure Association, Aggregation, Composition & Dependency Gang of Four (GOF) Design Patterns in .Net Understanding Inversion of Control, DI and SL Difference between WCF and Web API and WCF REST Routing in Asp.Net MVC with example Difference between Generics and Collections CRUD Operations using jQuery dialog and EF Asp.net MVC Request Life Cycle SQL Joins with C# LINQ
Like us on Facebook
Who The ?
If you're looking to learn a trick or technique which you have seen somewhere else. Let me know and I'll do my best to explain how it was done. If I don't know how to do, I'll take it as an exciting topic & I'll find upright resources and share.
More..
How The ?
Ultimately you come across to know new and fresh recipes. You're keen to learn those recipes but you don't know - how do that? Trust me, I have been there to help you for learning these new and fresh recipes.
More..
Disclaimer !
This is my personal blog and having articles on .net and others .net related technologies. The opinions expressed here are my own and not belongs to my employer or other organization. I have listed my own learning experience on this blog. Copyright 2012-2013. The content is copyright to Shailendra Chauhan and may not be reproduced on other websites without permission from the owner.