SlideShare a Scribd company logo
1 of 15
DATABASE MANAGEMENT SYSTEM -
JOINS & CONSTRAINTS
By
Ms.V.VENNILA,MCA.,M.Phil.,
Assistant Professor,
Bon Secours College for Women,Thanjavur.
SQL JOIN
 A SQL join is a Structured Query Language (SQL) instruction to combine data from two sets of data (i.e.
two tables). Before we dive into the details of a SQL join, let’s briefly discuss what SQL is, and why
someone would want to perform a SQL join.
 SQL is a special-purpose programming language designed for managing information in a relational
database management system (RDBMS).
Different Types of Joins
There are mainly four types of joins that you need to understand.
They are:
• INNER JOIN
• FULL JOIN
• LEFT JOIN
• RIGHT JOIN
INNER JOIN
This type of join returns those records which have matching values in both
tables. So, if you perform an INNER join operation between the Employee
table and the Projects table, all the tuples which have matching values in
both the tables will be given as output.
Syntax:
SELECT Table1.Column1,Table1.Column2,Table2.Column1,....
FROM Table1
INNER JOIN Table2
ON Table1.MatchingColumnName = Table2.MatchingColumnName;
FULL JOIN
Full Join or the Full Outer Join returns all those records which either have
a match in the left(Table1) or the right(Table2) table.
Syntax:
SELECT Table1.Column1,Table1.Column2,Table2.Column1,....
FROM Table1
FULL JOIN Table2
ON Table1.MatchingColumnName = Table2.MatchingColumnName;
LEFT JOIN
The LEFT JOIN or the LEFT OUTER JOIN returns all the records
from the left table and also those records which satisfy a condition
from the right table. Also, for the records having no matching values in
the right table, the output or the result-set will contain the NULL
values.
Syntax:
SELECT Table1.Column1,Table1.Column2,Table2.Column1,....
FROM Table1
LEFT JOIN Table2
ON Table1.MatchingColumnName = Table2.MatchingColumnName;
RIGHT JOIN
The RIGHT JOIN or the RIGHT OUTER JOIN returns all the
records from the right table and also those records which satisfy a
condition from the left table. Also, for the records having no
matching values in the left table, the output or the result-set will
contain the NULL values.
Syntax:
SELECT Table1.Column1,Table1.Column2,Table2.Column1,....
FROM Table1
RIGHT JOIN Table2
ON Table1.MatchingColumnName = Table2.MatchingColumnName;
Cross Join
The CROSS JOIN is a type of join in which a join clause is applied to
each row of a table to every row of the other table. Also, when the
WHERE condition is used, this type of JOIN behaves as an INNER
JOIN, and when the WHERE condition is not present, it behaves like a
CARTESIAN product.
SYNTAX
SELECT *
FROM employee CROSS JOIN department;
Self Join
SELF JOIN in other words is a join of a table to itself. This implies that
each row in a table is joined with itself.
SYNTAX
SELECT column_name(s)
FROM table1 T1, table1 T2
WHERE condition;
Integrity Constraints
Integrity Constraints
•Integrity constraints are a set of rules. It is used to maintain the quality of
information.
•Integrity constraints ensure that the data insertion, updating, and other
processes have to be performed in such a way that data integrity is not
affected.
•Thus, integrity constraint is used to guard against accidental damage to the
database.
Types of Integrity Constraint
some of the most commonly used constraints available in SQL
• NOT NULL - Ensures that a column cannot have a NULL value
• UNIQUE - Ensures that all values in a column are different
• PRIMARY KEY - A combination of a NOT NULL and UNIQUE. Uniquely identifies each row in a
table
• FOREIGN KEY - Uniquely identifies a row/record in another table
• CHECK - Ensures that all values in a column satisfies a specific condition
• DEFAULT - Sets a default value for a column when no value is specified
• INDEX - Used to create and retrieve data from the database very quickly
1. Domain constraints
• Domain constraints can be defined as the definition of a valid set of values for an attribute.
• The data type of domain includes string, character, integer, time, date, currency, etc. The
value of the attribute must be available in the corresponding domain.
Syntax
CHECK (search condition)
2. Entity integrity constraints
• The entity integrity constraint states that primary key value can't be null.
• This is because the primary key value is used to identify individual rows in relation and if the
primary key has a null value, then we can't identify those rows.
• A table can contain a null value other than the primary key field.
Syntax
PRIMRYKEY(attribute (,…))
3. Referential Integrity Constraints
• A referential integrity constraint is specified between two tables.
• In the Referential integrity constraints, if a foreign key in Table 1 refers to the Primary Key of Table 2,
then every value of the Foreign Key in Table 1 must be null or be available in Table 2.
4. Key constraints
• Keys are the entity set that is used to identify an entity within its entity set uniquely.
• An entity set can have multiple keys, but out of which one key will be the primary key. A primary key can
contain a unique and null value in the relational table.
NOT NULL:
This constraint tells that we cannot store a null value in a column. That is, if a column is specified
as NOT NULL then we will not be able to store null in this particular column any more.
Example using NOT NULL constraint
CREATE TABLE Student(s_id int NOT NULL, Name varchar(60), Age int);
UNIQUE:
This constraint when specified with a column, tells that all the values in the column must be unique. That
is, the values in any row of a column must not be repeated.
Using UNIQUE constraint when creating a Table (Table Level)
CREATE TABLE Student(s_id int NOT NULL UNIQUE, Name varchar(60), Age int);
Using UNIQUE constraint after Table is created (Column Level)
ALTER TABLE Student ADD UNIQUE(s_id);
PRIMARY KEY:
A primary key is a field which can uniquely identify each row in a table. And this constraint is used to
specify a field in a table as primary key.
Using PRIMARY KEY constraint at Table Level
CREATE table Student (s_id int PRIMARY KEY, Name varchar(60) NOT NULL, Age int);
Using PRIMARY KEY constraint at Column Level
ALTER table Student ADD PRIMARY KEY (s_id);
CHECK:
This constraint helps to validate the values of a column to meet a particular condition. That is, it helps to
ensure that the value stored in a column meets a specific condition.
Using CHECK constraint at Table Level
CREATE table Student(
s_id int NOT NULL CHECK(s_id > 0),
Name varchar(60) NOT NULL,
Age int
);
Using CHECK constraint at Column Level
ALTER table Student ADD CHECK(s_id > 0);
FOREIGN KEY:
A Foreign key is a field which can uniquely identify each row in a another table. And this
constraint is used to specify a field as Foreign key.
Using FOREIGN KEY constraint at Table Level
CREATE table Order_Detail(
order_id int PRIMARY KEY,
order_name varchar(60) NOT NULL,
c_id int FOREIGN KEY REFERENCES Customer_Detail(c_id)
);
Using FOREIGN KEY constraint at Column Level
ALTER table Order_Detail ADD FOREIGN KEY (c_id) REFERENCES Customer_Detail(c_id)
Thank you

More Related Content

What's hot (20)

SQL Constraints
SQL ConstraintsSQL Constraints
SQL Constraints
 
SQL Queries
SQL QueriesSQL Queries
SQL Queries
 
Using the set operators
Using the set operatorsUsing the set operators
Using the set operators
 
Types of keys in dbms
Types of keys in dbmsTypes of keys in dbms
Types of keys in dbms
 
Sql Tutorials
Sql TutorialsSql Tutorials
Sql Tutorials
 
Constraints In Sql
Constraints In SqlConstraints In Sql
Constraints In Sql
 
Create table
Create tableCreate table
Create table
 
Types of keys dbms
Types of keys dbmsTypes of keys dbms
Types of keys dbms
 
DBMS: Types of keys
DBMS:  Types of keysDBMS:  Types of keys
DBMS: Types of keys
 
SQL Commands
SQL Commands SQL Commands
SQL Commands
 
Introduction to-sql
Introduction to-sqlIntroduction to-sql
Introduction to-sql
 
Types of keys in database | SQL
Types of keys in database | SQLTypes of keys in database | SQL
Types of keys in database | SQL
 
Types Of Keys in DBMS
Types Of Keys in DBMSTypes Of Keys in DBMS
Types Of Keys in DBMS
 
Integrity Constraints
Integrity ConstraintsIntegrity Constraints
Integrity Constraints
 
SQL Overview
SQL OverviewSQL Overview
SQL Overview
 
Database Keys & Relationship
Database Keys & RelationshipDatabase Keys & Relationship
Database Keys & Relationship
 
SQL JOINS
SQL JOINSSQL JOINS
SQL JOINS
 
Sql join
Sql  joinSql  join
Sql join
 
Alter table command
Alter table commandAlter table command
Alter table command
 
SQL Functions
SQL FunctionsSQL Functions
SQL Functions
 

Similar to Joins & constraints

Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptxSherinRappai
 
Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptxSherinRappai1
 
SQL -Beginner To Intermediate Level.pdf
SQL -Beginner To Intermediate Level.pdfSQL -Beginner To Intermediate Level.pdf
SQL -Beginner To Intermediate Level.pdfDraguClaudiu
 
Relational database management system
Relational database management systemRelational database management system
Relational database management systemPraveen Soni
 
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 analysisSanSan149
 
RDBMS Lab03 applying constraints (UIU)
RDBMS Lab03 applying constraints (UIU)RDBMS Lab03 applying constraints (UIU)
RDBMS Lab03 applying constraints (UIU)Muhammad T Q Nafis
 
Sql overview-1232931296681161-1
Sql overview-1232931296681161-1Sql overview-1232931296681161-1
Sql overview-1232931296681161-1sagaroceanic11
 
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) .pptxjainendraKUMAR55
 
DATABASE MANAGMENT SYSTEM (DBMS) AND SQL
DATABASE MANAGMENT SYSTEM (DBMS) AND SQLDATABASE MANAGMENT SYSTEM (DBMS) AND SQL
DATABASE MANAGMENT SYSTEM (DBMS) AND SQLDev Chauhan
 
Sql(structured query language)
Sql(structured query language)Sql(structured query language)
Sql(structured query language)Ishucs
 
SQL Server Learning Drive
SQL Server Learning Drive SQL Server Learning Drive
SQL Server Learning Drive TechandMate
 
Java class 8
Java class 8Java class 8
Java class 8Edureka!
 

Similar to Joins & constraints (20)

Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptx
 
Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptx
 
Sql
SqlSql
Sql
 
SQL -Beginner To Intermediate Level.pdf
SQL -Beginner To Intermediate Level.pdfSQL -Beginner To Intermediate Level.pdf
SQL -Beginner To Intermediate Level.pdf
 
Relational database management system
Relational database management systemRelational database management system
Relational database management system
 
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 introduction
Sql introductionSql introduction
Sql introduction
 
Integrity and security
Integrity and securityIntegrity and security
Integrity and security
 
RDBMS Lab03 applying constraints (UIU)
RDBMS Lab03 applying constraints (UIU)RDBMS Lab03 applying constraints (UIU)
RDBMS Lab03 applying constraints (UIU)
 
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
 
ER diagram
ER diagramER diagram
ER diagram
 
DATABASE MANAGMENT SYSTEM (DBMS) AND SQL
DATABASE MANAGMENT SYSTEM (DBMS) AND SQLDATABASE MANAGMENT SYSTEM (DBMS) AND SQL
DATABASE MANAGMENT SYSTEM (DBMS) AND SQL
 
Sql(structured query language)
Sql(structured query language)Sql(structured query language)
Sql(structured query language)
 
Database constraints
Database constraintsDatabase constraints
Database constraints
 
SQL Server Learning Drive
SQL Server Learning Drive SQL Server Learning Drive
SQL Server Learning Drive
 
MULTIPLE TABLES
MULTIPLE TABLES MULTIPLE TABLES
MULTIPLE TABLES
 
DBMS.pptx
DBMS.pptxDBMS.pptx
DBMS.pptx
 
Java class 8
Java class 8Java class 8
Java class 8
 
SQL Session 2.pdf
SQL Session 2.pdfSQL Session 2.pdf
SQL Session 2.pdf
 

More from VENNILAV6

WORKING WITH GRAPHICS
WORKING WITH GRAPHICSWORKING WITH GRAPHICS
WORKING WITH GRAPHICSVENNILAV6
 
CREATING A MASTER PAGE
CREATING A MASTER PAGECREATING A MASTER PAGE
CREATING A MASTER PAGEVENNILAV6
 
CREATING A NEW PUBLICATION IN PAGEMAKER
CREATING A NEW PUBLICATION IN PAGEMAKERCREATING A NEW PUBLICATION IN PAGEMAKER
CREATING A NEW PUBLICATION IN PAGEMAKERVENNILAV6
 
Relational algebra
Relational algebraRelational algebra
Relational algebraVENNILAV6
 
STRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIESSTRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIESVENNILAV6
 
Database architecture
Database architectureDatabase architecture
Database architectureVENNILAV6
 
Data definition language
Data definition languageData definition language
Data definition languageVENNILAV6
 
INTERCONNECTION STRUCTURE
INTERCONNECTION STRUCTUREINTERCONNECTION STRUCTURE
INTERCONNECTION STRUCTUREVENNILAV6
 
CACHE MEMORY
CACHE MEMORYCACHE MEMORY
CACHE MEMORYVENNILAV6
 
Machine control flow
Machine control flowMachine control flow
Machine control flowVENNILAV6
 
COMPUTER FUNCTIONS
COMPUTER FUNCTIONSCOMPUTER FUNCTIONS
COMPUTER FUNCTIONSVENNILAV6
 
EXTERNAL DEVICE
EXTERNAL DEVICEEXTERNAL DEVICE
EXTERNAL DEVICEVENNILAV6
 
CORELDRAW EXAMPLES
CORELDRAW EXAMPLESCORELDRAW EXAMPLES
CORELDRAW EXAMPLESVENNILAV6
 
BASICS OF DATA STRUCTURE
BASICS OF DATA STRUCTUREBASICS OF DATA STRUCTURE
BASICS OF DATA STRUCTUREVENNILAV6
 
object oriented system development
object oriented system development object oriented system development
object oriented system development VENNILAV6
 
virtual function
virtual functionvirtual function
virtual functionVENNILAV6
 
constructor and destructor
constructor and destructorconstructor and destructor
constructor and destructorVENNILAV6
 
BASICS OF MOBILE COMPUTING
BASICS OF MOBILE COMPUTINGBASICS OF MOBILE COMPUTING
BASICS OF MOBILE COMPUTINGVENNILAV6
 
BASICS OF JAVA
BASICS OF JAVABASICS OF JAVA
BASICS OF JAVAVENNILAV6
 

More from VENNILAV6 (20)

WORKING WITH GRAPHICS
WORKING WITH GRAPHICSWORKING WITH GRAPHICS
WORKING WITH GRAPHICS
 
CREATING A MASTER PAGE
CREATING A MASTER PAGECREATING A MASTER PAGE
CREATING A MASTER PAGE
 
CREATING A NEW PUBLICATION IN PAGEMAKER
CREATING A NEW PUBLICATION IN PAGEMAKERCREATING A NEW PUBLICATION IN PAGEMAKER
CREATING A NEW PUBLICATION IN PAGEMAKER
 
Relational algebra
Relational algebraRelational algebra
Relational algebra
 
STRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIESSTRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIES
 
Database architecture
Database architectureDatabase architecture
Database architecture
 
Data definition language
Data definition languageData definition language
Data definition language
 
INTERCONNECTION STRUCTURE
INTERCONNECTION STRUCTUREINTERCONNECTION STRUCTURE
INTERCONNECTION STRUCTURE
 
CACHE MEMORY
CACHE MEMORYCACHE MEMORY
CACHE MEMORY
 
Machine control flow
Machine control flowMachine control flow
Machine control flow
 
COMPUTER FUNCTIONS
COMPUTER FUNCTIONSCOMPUTER FUNCTIONS
COMPUTER FUNCTIONS
 
EXTERNAL DEVICE
EXTERNAL DEVICEEXTERNAL DEVICE
EXTERNAL DEVICE
 
CORELDRAW EXAMPLES
CORELDRAW EXAMPLESCORELDRAW EXAMPLES
CORELDRAW EXAMPLES
 
BASICS OF DATA STRUCTURE
BASICS OF DATA STRUCTUREBASICS OF DATA STRUCTURE
BASICS OF DATA STRUCTURE
 
object oriented system development
object oriented system development object oriented system development
object oriented system development
 
virtual function
virtual functionvirtual function
virtual function
 
constructor and destructor
constructor and destructorconstructor and destructor
constructor and destructor
 
INHERITANCE
INHERITANCEINHERITANCE
INHERITANCE
 
BASICS OF MOBILE COMPUTING
BASICS OF MOBILE COMPUTINGBASICS OF MOBILE COMPUTING
BASICS OF MOBILE COMPUTING
 
BASICS OF JAVA
BASICS OF JAVABASICS OF JAVA
BASICS OF JAVA
 

Recently uploaded

Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 

Recently uploaded (20)

Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 

Joins & constraints

  • 1. DATABASE MANAGEMENT SYSTEM - JOINS & CONSTRAINTS By Ms.V.VENNILA,MCA.,M.Phil., Assistant Professor, Bon Secours College for Women,Thanjavur.
  • 2. SQL JOIN  A SQL join is a Structured Query Language (SQL) instruction to combine data from two sets of data (i.e. two tables). Before we dive into the details of a SQL join, let’s briefly discuss what SQL is, and why someone would want to perform a SQL join.  SQL is a special-purpose programming language designed for managing information in a relational database management system (RDBMS). Different Types of Joins There are mainly four types of joins that you need to understand. They are: • INNER JOIN • FULL JOIN • LEFT JOIN • RIGHT JOIN
  • 3.
  • 4. INNER JOIN This type of join returns those records which have matching values in both tables. So, if you perform an INNER join operation between the Employee table and the Projects table, all the tuples which have matching values in both the tables will be given as output. Syntax: SELECT Table1.Column1,Table1.Column2,Table2.Column1,.... FROM Table1 INNER JOIN Table2 ON Table1.MatchingColumnName = Table2.MatchingColumnName; FULL JOIN Full Join or the Full Outer Join returns all those records which either have a match in the left(Table1) or the right(Table2) table. Syntax: SELECT Table1.Column1,Table1.Column2,Table2.Column1,.... FROM Table1 FULL JOIN Table2 ON Table1.MatchingColumnName = Table2.MatchingColumnName;
  • 5. LEFT JOIN The LEFT JOIN or the LEFT OUTER JOIN returns all the records from the left table and also those records which satisfy a condition from the right table. Also, for the records having no matching values in the right table, the output or the result-set will contain the NULL values. Syntax: SELECT Table1.Column1,Table1.Column2,Table2.Column1,.... FROM Table1 LEFT JOIN Table2 ON Table1.MatchingColumnName = Table2.MatchingColumnName; RIGHT JOIN The RIGHT JOIN or the RIGHT OUTER JOIN returns all the records from the right table and also those records which satisfy a condition from the left table. Also, for the records having no matching values in the left table, the output or the result-set will contain the NULL values. Syntax: SELECT Table1.Column1,Table1.Column2,Table2.Column1,.... FROM Table1 RIGHT JOIN Table2 ON Table1.MatchingColumnName = Table2.MatchingColumnName;
  • 6. Cross Join The CROSS JOIN is a type of join in which a join clause is applied to each row of a table to every row of the other table. Also, when the WHERE condition is used, this type of JOIN behaves as an INNER JOIN, and when the WHERE condition is not present, it behaves like a CARTESIAN product. SYNTAX SELECT * FROM employee CROSS JOIN department; Self Join SELF JOIN in other words is a join of a table to itself. This implies that each row in a table is joined with itself. SYNTAX SELECT column_name(s) FROM table1 T1, table1 T2 WHERE condition;
  • 7. Integrity Constraints Integrity Constraints •Integrity constraints are a set of rules. It is used to maintain the quality of information. •Integrity constraints ensure that the data insertion, updating, and other processes have to be performed in such a way that data integrity is not affected. •Thus, integrity constraint is used to guard against accidental damage to the database.
  • 8. Types of Integrity Constraint
  • 9. some of the most commonly used constraints available in SQL • NOT NULL - Ensures that a column cannot have a NULL value • UNIQUE - Ensures that all values in a column are different • PRIMARY KEY - A combination of a NOT NULL and UNIQUE. Uniquely identifies each row in a table • FOREIGN KEY - Uniquely identifies a row/record in another table • CHECK - Ensures that all values in a column satisfies a specific condition • DEFAULT - Sets a default value for a column when no value is specified • INDEX - Used to create and retrieve data from the database very quickly
  • 10. 1. Domain constraints • Domain constraints can be defined as the definition of a valid set of values for an attribute. • The data type of domain includes string, character, integer, time, date, currency, etc. The value of the attribute must be available in the corresponding domain. Syntax CHECK (search condition) 2. Entity integrity constraints • The entity integrity constraint states that primary key value can't be null. • This is because the primary key value is used to identify individual rows in relation and if the primary key has a null value, then we can't identify those rows. • A table can contain a null value other than the primary key field. Syntax PRIMRYKEY(attribute (,…))
  • 11. 3. Referential Integrity Constraints • A referential integrity constraint is specified between two tables. • In the Referential integrity constraints, if a foreign key in Table 1 refers to the Primary Key of Table 2, then every value of the Foreign Key in Table 1 must be null or be available in Table 2. 4. Key constraints • Keys are the entity set that is used to identify an entity within its entity set uniquely. • An entity set can have multiple keys, but out of which one key will be the primary key. A primary key can contain a unique and null value in the relational table.
  • 12. NOT NULL: This constraint tells that we cannot store a null value in a column. That is, if a column is specified as NOT NULL then we will not be able to store null in this particular column any more. Example using NOT NULL constraint CREATE TABLE Student(s_id int NOT NULL, Name varchar(60), Age int); UNIQUE: This constraint when specified with a column, tells that all the values in the column must be unique. That is, the values in any row of a column must not be repeated. Using UNIQUE constraint when creating a Table (Table Level) CREATE TABLE Student(s_id int NOT NULL UNIQUE, Name varchar(60), Age int); Using UNIQUE constraint after Table is created (Column Level) ALTER TABLE Student ADD UNIQUE(s_id);
  • 13. PRIMARY KEY: A primary key is a field which can uniquely identify each row in a table. And this constraint is used to specify a field in a table as primary key. Using PRIMARY KEY constraint at Table Level CREATE table Student (s_id int PRIMARY KEY, Name varchar(60) NOT NULL, Age int); Using PRIMARY KEY constraint at Column Level ALTER table Student ADD PRIMARY KEY (s_id); CHECK: This constraint helps to validate the values of a column to meet a particular condition. That is, it helps to ensure that the value stored in a column meets a specific condition. Using CHECK constraint at Table Level CREATE table Student( s_id int NOT NULL CHECK(s_id > 0), Name varchar(60) NOT NULL, Age int ); Using CHECK constraint at Column Level ALTER table Student ADD CHECK(s_id > 0);
  • 14. FOREIGN KEY: A Foreign key is a field which can uniquely identify each row in a another table. And this constraint is used to specify a field as Foreign key. Using FOREIGN KEY constraint at Table Level CREATE table Order_Detail( order_id int PRIMARY KEY, order_name varchar(60) NOT NULL, c_id int FOREIGN KEY REFERENCES Customer_Detail(c_id) ); Using FOREIGN KEY constraint at Column Level ALTER table Order_Detail ADD FOREIGN KEY (c_id) REFERENCES Customer_Detail(c_id)