- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Environmental Science
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is Primary Key in SQL ?
Primary Key is a constraint in SQL. So, before understanding what exactly is a primary key, let’s understand what exactly is a constraint in SQL. Constraints are the rules enforced on data columns on a table. These are used to limit the type of data that can go into a table. Constraints can either be column level or table level.
Let’s look at the different types of constraints which are present in SQL:
Constraint | Description |
NOT NULL | Ensures that a column cannot have a NULL value. |
DEFAULT | Provides a default value for a column when none is specified. |
UNIQUE | Ensures that all the values in a column are different |
PRIMARY | Uniquely identifies each row/record in a database table |
FOREIGN | Uniquely identifies a row/record in any another database table |
CHECK | The CHECK constraint ensures that all values in a column satisfy certain conditions. |
INDEX | Used to create and retrieve data from the database very quickly. |
You can consider Primary Key constraint to be a combination of UNIQUE and NOT NULL constraint. This means that if a column is set as a primary key, then this particular column cannot have any null values present in it and also all the values present in this column must be unique.
- Related Questions & Answers
- What is a unique key in SQL ?
- How to insert date in SQL ?
- How to change a table name in SQL ?
- What is SQL injection ?
- How to Create a Table in SQL – Postgres and MySQL Example Query
- What is Data Integrity ?
- How to create a table in SQL ?
- What are the types of SQL Queries ?
- How to delete a row in SQL ?
- What is OLTP ?
- How to create a database in SQL?
- What is SQL server ?
- What is a trigger in SQL ?
- What are Nested Triggers ?
- How to delete a column in SQL ?
- How can I see all tables in SQL?
Advertisements
ads