Christmas Special : Upto 40% OFF! + 2 free courses  - SCHEDULE CALL

- SQL Server Blogs -

Different Types of SQL Keys: Example and Uses



Introduction

A key is an attribute or set of attributes in a relation that uniquely identifies a tuple in a relation. The objective of this blog is to make you familiar with different types of keys with examples and how they can be used within a database app. Before we move to the actual discussion, let us see different types of keys and a list of topics to be covered in the blog,

Different types of keys:

  • Super Key
  • Candidate Key
  • Primary Key
  • Foreign Key
  • Alternate Key
  • Composite Key
  • Unique Key

Read: What is Database? A Definitive Guide

Super Key:

  • A set of attributes which contains a key.
  • A Super key is the most general type of a key.
  • There is no practical use of this key.
  • Super key can be Redundant.

NOTE: All keys are super key. EXAMPLE: 

STUDENT ID STUDENT ROLLNO STUDENT NAME STUDENT MARKS
101 1 James 68
102 2 Sam 73
103 3 David 94
104 4 James 73

Suppose we have a table that holds all the students in a college, and that table is called students information. The table has columns called STUDENT ID, STUDENT ROLLNO, STUDENT NAME, and STUDENT MARKS. Every student has his/her own STUDENT ID, STUDENT ROLLNO, so that value is always unique in each and every row.

Candidate Key:

Candidate Key can be defined as a set of one or more fields/columns that can identify a record uniquely in a table like primary key or we can also say that other fields than a primary key which can become primary key and a table can have more than one candidate key. Each candidate key can work as primary key if required in any case.

To know more about SQL keys, register for our demo class and interact with our mentors LIVE and know all about SQL.

Learn SQL Server in the Easiest Way

  • Learn from the videos
  • Learn anytime anywhere
  • Pocket-friendly mode of learning
  • Complimentary eBook available

For Example: Suppose a table consists of Employee data with fields Employee_Name, Employee_Address,Employee_Id , Employee_Designation. Employee_PANNo and Employee_PhoneNo  in this table Employee_PhoneNo and Employee_PANNo are Candidate Keys as these two fields can also work as a candidate key.

Composite/Compound Key:

Composite Key can be defined as a combination of more than one fields/columns of a table to uniquely identify the record. Fields which can be combined to make composite key can be a candidate,  primary key.

For Example: Suppose a table consists of Employee data with fields Employee_Name, Employee_Address, Employee_Id , Employee_Designation, Employee_PANNO and Employee_PhoneNo in this table to build a composite key we combine Employee_Id and Employee_PhoneNo to fetch data from the table.

Read: Top 50 SAS Interview Questions and Answers For Fresher, Experienced

Foreign Key:

Foreign Key can be defined as a field/column in the Company table that is Primary key in Employee table. It can also accept multiple null values and duplicate values. This can be easily understood with the help of example given below.

SQL Server Training & Certification

  • No cost for a Demo Class
  • Industry Expert as your Trainer
  • Available as per your schedule
  • Customer Support Available

For Example: We can have an Employee_Id column in the Company table which is pointing to Employee_Id column in an Employee table where it a primary key. So with the help of a foreign key, we can easily identify the data from tables. 

Primary Key:

Primary key can be defined as a set of one or more fields/columns of a table that uniquely identify a record in a database table. A record can be uniquely identified when the column which includes unique value like Employee_Id of an employee from an organization. It will not accept null values and duplicate values. Only one primary key can exist in a single table not more than one.

Example: Suppose a table consists of Employee data with fields Employee_Name, Employee_Address, Employee_Id and Employee_Designation so in this table only one field is there which is used to uniquely identify detail of Employee that is Employee_Id. Read More: Different Types of SQL Database Functions

Unique Key:

The unique key can be defined as a set of one or more fields/columns of a table that have the capability to uniquely identify a record in the database table. We can have other fields also in a table beyond primary key which is also able to uniquely identify the record. It can accept only one null value and it cannot have duplicate values in it.

SQL Server Training & Certification

  • Personalized Free Consultation
  • Access to Our Learning Management System
  • Access to Our Course Curriculum
  • Be a Part of Our Free Demo Class

Example: Suppose a table consists of Employee data with fields Employee_Name, Employee_Address, Employee_Id, Employee_Designation and Employee_PhoneNo so in this table except for Employee_Id we also have an another field named Employee_PhoneNo which is can also be used to uniquely identify the record and can be termed as Unique Key.

Summary:

This SQL blog gives you a practical idea of keys with examples and how to use them within a database app. It would be great if you can practice these or more similar examples on your system. 

Join our self-learning courses in 2020 at attractive discounts available and boost your practical knowledge right away!

Read: MSBI Certification & Learning Path: My Success Story You Must Know

SQL Tutorial Overview

fbicons FaceBook twitterTwitter lingedinLinkedIn pinterest Pinterest emailEmail

     Logo

    JanBask Training

    A dynamic, highly professional, and a global online training course provider committed to propelling the next generation of technology learners with a whole new way of training experience.


  • fb-15
  • twitter-15
  • linkedin-15

Comments

Trending Courses

Cyber Security Course

Cyber Security

  • Introduction to cybersecurity
  • Cryptography and Secure Communication 
  • Cloud Computing Architectural Framework
  • Security Architectures and Models
Cyber Security Course

Upcoming Class

-1 day 21 Dec 2024

QA Course

QA

  • Introduction and Software Testing
  • Software Test Life Cycle
  • Automation Testing and API Testing
  • Selenium framework development using Testing
QA Course

Upcoming Class

6 days 28 Dec 2024

Salesforce Course

Salesforce

  • Salesforce Configuration Introduction
  • Security & Automation Process
  • Sales & Service Cloud
  • Apex Programming, SOQL & SOSL
Salesforce Course

Upcoming Class

8 days 30 Dec 2024

Business Analyst Course

Business Analyst

  • BA & Stakeholders Overview
  • BPMN, Requirement Elicitation
  • BA Tools & Design Documents
  • Enterprise Analysis, Agile & Scrum
Business Analyst Course

Upcoming Class

5 days 27 Dec 2024

MS SQL Server Course

MS SQL Server

  • Introduction & Database Query
  • Programming, Indexes & System Functions
  • SSIS Package Development Procedures
  • SSRS Report Design
MS SQL Server Course

Upcoming Class

5 days 27 Dec 2024

Data Science Course

Data Science

  • Data Science Introduction
  • Hadoop and Spark Overview
  • Python & Intro to R Programming
  • Machine Learning
Data Science Course

Upcoming Class

12 days 03 Jan 2025

DevOps Course

DevOps

  • Intro to DevOps
  • GIT and Maven
  • Jenkins & Ansible
  • Docker and Cloud Computing
DevOps Course

Upcoming Class

-1 day 21 Dec 2024

Hadoop Course

Hadoop

  • Architecture, HDFS & MapReduce
  • Unix Shell & Apache Pig Installation
  • HIVE Installation & User-Defined Functions
  • SQOOP & Hbase Installation
Hadoop Course

Upcoming Class

6 days 28 Dec 2024

Python Course

Python

  • Features of Python
  • Python Editors and IDEs
  • Data types and Variables
  • Python File Operation
Python Course

Upcoming Class

-1 day 21 Dec 2024

Artificial Intelligence Course

Artificial Intelligence

  • Components of AI
  • Categories of Machine Learning
  • Recurrent Neural Networks
  • Recurrent Neural Networks
Artificial Intelligence Course

Upcoming Class

13 days 04 Jan 2025

Machine Learning Course

Machine Learning

  • Introduction to Machine Learning & Python
  • Machine Learning: Supervised Learning
  • Machine Learning: Unsupervised Learning
Machine Learning Course

Upcoming Class

5 days 27 Dec 2024

 Tableau Course

Tableau

  • Introduction to Tableau Desktop
  • Data Transformation Methods
  • Configuring tableau server
  • Integration with R & Hadoop
 Tableau Course

Upcoming Class

6 days 28 Dec 2024

Search Posts

Reset

Receive Latest Materials and Offers on SQL Server Course

Interviews