SlideShare a Scribd company logo
1 of 6
Download to read offline
SQL Session 2
UTKARSH GAIKWAD
Table Constraints in SQL
Types of Table Constraints:
➢ NOT NULL Constraint: Ensures that a column cannot have a NULL value.
➢UNIQUE Constraint: Ensures that all values in a column are unique.
➢PRIMARY KEY Constraint: A combination of NOT NULL and UNIQUE constraints. It ensures that
a column or set of columns uniquely identify each row in the table.
➢FOREIGN KEY Constraint: Ensures that values in a column (or a set of columns) match the
values in a column(s) of another table (i.e., references the primary key of another table).
➢CHECK Constraint: Ensures that the data entered in a column satisfies a specific condition.
➢DEFAULT Constraint: Provides a default value for a column when no value is specified.
Departments table
CREATE TABLE Departments (
DepartmentID INT PRIMARY KEY,
DepartmentName VARCHAR(50) NOT NULL
);
Employees Table
CREATE TABLE Employees (
EmployeeID INT PRIMARY KEY,
FirstName VARCHAR(50) NOT NULL,
LastName VARCHAR(50) NOT NULL,
Email VARCHAR(100) UNIQUE,
DepartmentID INT FOREIGN KEY,
Salary DECIMAL(10, 2) CHECK (Salary > 0),
HireDate DATE DEFAULT '2023-01-01’,
CONSTRAINT fk_DepratmentID
FOREIGN KEY (DepartmentID)
REFERENCES Departments(DepartmentID) );
Foreign Key vs Primary Key
Employee Department
Primary Key
For Employee Table
Foreign Key for
Employee Table Primary Key
For Department Table
Thank You
FOR ANY QUERIES PING ME ON SKYPE GROUP

More Related Content

Similar to SQL Session 2.pdf

SQL Constraintspending.pptx
SQL Constraintspending.pptxSQL Constraintspending.pptx
SQL Constraintspending.pptx
AryanGour1
 
Web app development_my_sql_09
Web app development_my_sql_09Web app development_my_sql_09
Web app development_my_sql_09
Hassen Poreya
 
Constraints
ConstraintsConstraints
Constraints
punu_82
 
Sql ch 12 - creating database
Sql ch 12 - creating databaseSql ch 12 - creating database
Sql ch 12 - creating database
Mukesh Tekwani
 
Mysql 120831075600-phpapp01
Mysql 120831075600-phpapp01Mysql 120831075600-phpapp01
Mysql 120831075600-phpapp01
sagaroceanic11
 
oracle Sql constraint
oracle  Sql constraint oracle  Sql constraint
oracle Sql constraint
home
 
Sql overview-1232931296681161-1
Sql overview-1232931296681161-1Sql overview-1232931296681161-1
Sql overview-1232931296681161-1
sagaroceanic11
 

Similar to SQL Session 2.pdf (20)

1.3 sql constraints
1.3 sql constraints1.3 sql constraints
1.3 sql constraints
 
Sql Constraints
Sql ConstraintsSql Constraints
Sql Constraints
 
03Constraints - last.pdf
03Constraints - last.pdf03Constraints - last.pdf
03Constraints - last.pdf
 
Relational database management system
Relational database management systemRelational database management system
Relational database management system
 
Create table
Create tableCreate table
Create table
 
SQL Constraintspending.pptx
SQL Constraintspending.pptxSQL Constraintspending.pptx
SQL Constraintspending.pptx
 
Web app development_my_sql_09
Web app development_my_sql_09Web app development_my_sql_09
Web app development_my_sql_09
 
Entigrity constraint
Entigrity constraintEntigrity constraint
Entigrity constraint
 
Constraints
ConstraintsConstraints
Constraints
 
SQL
SQLSQL
SQL
 
Sql ch 12 - creating database
Sql ch 12 - creating databaseSql ch 12 - creating database
Sql ch 12 - creating database
 
Integrity and security
Integrity and securityIntegrity and security
Integrity and security
 
SQL Overview
SQL OverviewSQL Overview
SQL Overview
 
Mysql 120831075600-phpapp01
Mysql 120831075600-phpapp01Mysql 120831075600-phpapp01
Mysql 120831075600-phpapp01
 
oracle Sql constraint
oracle  Sql constraint oracle  Sql constraint
oracle Sql constraint
 
Les10
Les10Les10
Les10
 
Constraints
ConstraintsConstraints
Constraints
 
joins and subqueries in big data analysis
joins and subqueries in big data analysisjoins and subqueries in big data analysis
joins and subqueries in big data analysis
 
Sql overview-1232931296681161-1
Sql overview-1232931296681161-1Sql overview-1232931296681161-1
Sql overview-1232931296681161-1
 
DBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptxDBMS and SQL(structured query language) .pptx
DBMS and SQL(structured query language) .pptx
 

Recently uploaded

Recently uploaded (20)

Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
latest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answerslatest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answers
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Simple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfSimple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdf
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111
 

SQL Session 2.pdf

  • 2. Table Constraints in SQL Types of Table Constraints: ➢ NOT NULL Constraint: Ensures that a column cannot have a NULL value. ➢UNIQUE Constraint: Ensures that all values in a column are unique. ➢PRIMARY KEY Constraint: A combination of NOT NULL and UNIQUE constraints. It ensures that a column or set of columns uniquely identify each row in the table. ➢FOREIGN KEY Constraint: Ensures that values in a column (or a set of columns) match the values in a column(s) of another table (i.e., references the primary key of another table). ➢CHECK Constraint: Ensures that the data entered in a column satisfies a specific condition. ➢DEFAULT Constraint: Provides a default value for a column when no value is specified.
  • 3. Departments table CREATE TABLE Departments ( DepartmentID INT PRIMARY KEY, DepartmentName VARCHAR(50) NOT NULL );
  • 4. Employees Table CREATE TABLE Employees ( EmployeeID INT PRIMARY KEY, FirstName VARCHAR(50) NOT NULL, LastName VARCHAR(50) NOT NULL, Email VARCHAR(100) UNIQUE, DepartmentID INT FOREIGN KEY, Salary DECIMAL(10, 2) CHECK (Salary > 0), HireDate DATE DEFAULT '2023-01-01’, CONSTRAINT fk_DepratmentID FOREIGN KEY (DepartmentID) REFERENCES Departments(DepartmentID) );
  • 5. Foreign Key vs Primary Key Employee Department Primary Key For Employee Table Foreign Key for Employee Table Primary Key For Department Table
  • 6. Thank You FOR ANY QUERIES PING ME ON SKYPE GROUP