
DBMS-2
Presentation
•
Computers
•
University
•
Hard
Veda V
Used 8+ times
FREE Resource
24 Slides • 4 Questions
1
DBMS-Concepts
(Session 2)
By
V.Veda Sri
Asst.Professor
Dept. of Comp.Science
RBVRR Women's College
2
SQL JOIN
In SQL, JOIN clause is used to combine the records from two or more tables in a database.
Types of SQL JOIN: INNER JOIN, LEFT JOIN, RIGHT JOIN ,FULL JOIN.
3
4
1. INNER JOIN
In SQL, INNER JOIN selects records that have matching values in both tables as long as the condition is satisfied. It returns the combination of all rows from both the tables where the condition satisfies.
Syntax
SELECT table1.column1, table1.column2, table2.column1,.... FROM table1 INNER JOIN table2 ON table1.matching_column = table2.matching_column;
5
Query
SELECT EMPLOYEE.EMP_NAME,
PROJECT.DEPARTMENT FROM EMPLOYEE
INNER JOIN PROJECT
ON PROJECT.EMP_ID = EMPLOYEE.EMP_ID;
6
2. LEFT JOIN
The SQL left join returns all the values from left table and the matching values from the right table. If there is no matching join value, it will return NULL.
Syntax
SELECT table1.column1, table1.column2, table2.column1,.... FROM table1 LEFT JOIN table2 ON table1.matching_column = table2.matching_column;
7
Query
SELECT EMPLOYEE.EMP_NAME,
PROJECT.DEPARTMENT
FROM EMPLOYEE
LEFT JOIN PROJECT
ON PROJECT.EMP_ID = EMPLOYEE.EMP_ID;
8
3. RIGHT JOIN
In SQL, RIGHT JOIN returns all the values from the values from the rows of right table and the matched values from the left table. If there is no matching in both tables, it will return NULL.
Syntax
SELECT table1.column1, table1.column2, table2.column1,.... FROM table1 RIGHT JOIN table2 ON table1.matching_column = table2.matching_column;
9
Query
SELECT EMPLOYEE.EMP_NAME,
PROJECT.DEPARTMENT
FROM EMPLOYEE
RIGHT JOIN PROJECT ON PROJECT.EMP_ID = EMPLOYEE.EMP_ID;
10
4. FULL JOIN
In SQL, FULL JOIN is the result of a combination of both left and right outer join. Join tables have all the records from both tables. It puts NULL on the place of matches not found.
Syntax
SELECT table1.column1, table1.column2, table2.column1,.... FROM table1 FULL JOIN table2 ON table1.matching_column = table2.matching_column;
11
Query
SELECT EMPLOYEE.EMP_NAME,
PROJECT.DEPARTMENT
FROM EMPLOYEE
FULL JOIN PROJECT ON PROJECT.EMP_ID = EMPLOYEE.EMP_ID;
12
13
Multiple Choice
Insert the missing parts in the JOIN clause to join the two tables Orders and Customers, using the CustomerID field in both tables as the relationship between the two tables.
SELECT *
FROM Orders
LEFT JOIN Customers
_______=________
ON Orders.CustomerID=
Customers.CustomerID;
Customers.CustomerID=
orders.customerID
Orders.CustomerID=
Customers.CustomerID;
ON Customers.CustomerID=
Orders.CustomerID
14
Multiple Choice
Choose the correct JOIN clause to select all the records from the Customers table plus all the matches in the Orders table.
SELECT *
FROM Orders
------------------------
ON Orders.CustomerID=Customers.CustomerID;
JOIN Customers
RIGHT JOIN Customers
RIGHT JOIN Orders
OUTER JOIN Customers
15
Multiple Choice
The LEFT JOIN keyword returns all records from the left table (Customers), even if there are ______ in the right table (Orders).
matches
no matches
16
Multiple Choice
The FULL OUTER JOIN keyword returns all matching records from both tables whether the other table _______.
only matches
only not matches
matches or not
None
17
18
SQL Constraints
SQL constraints are used to specify rules for the data in a table.
This ensures the accuracy and reliability of the data in the table.
Constraints can be column level or table level.
19
The following constraints are commonly used 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.
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
20
Example
CREATE TABLE Persons (
ID int NOT NULL UNIQUE/PRIMARY KEY,
LastName varchar(255) NOT NULL,
FirstName varchar(255) NOT NULL,
Age int CHECK (Age>=18),
City varchar(255) DEFAULT 'Sandnes'
);
21
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.
22
Example
23
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.
24
Example
25
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.
26
Example
27
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.
28
Example
DBMS-Concepts
(Session 2)
By
V.Veda Sri
Asst.Professor
Dept. of Comp.Science
RBVRR Women's College
Show answer
Auto Play
Slide 1 / 28
SLIDE
Similar Resources on Wayground
20 questions
compound sentences
Presentation
•
University
26 questions
Medan Magnet
Presentation
•
University
22 questions
wh questions
Presentation
•
University
20 questions
Pointers in C
Presentation
•
12th Grade
22 questions
Java + SQL Unit 3
Presentation
•
University
24 questions
Tutorium 11
Presentation
•
University
22 questions
United Nations
Presentation
•
Professional Development
23 questions
Matrix
Presentation
•
12th Grade
Popular Resources on Wayground
10 questions
HCS SCI 03 Summer School Assessment 1
Quiz
•
3rd Grade
15 questions
HCS SCI 05 Summer School Assessment 1 Review
Quiz
•
5th Grade
22 questions
Day 9 Equations and Inequalities Review
Quiz
•
9th Grade
10 questions
Writing and Identifying Ratios Practice
Quiz
•
5th - 6th Grade
7 questions
PYRAMID PERSPECTIVES part 1
Presentation
•
9th - 12th Grade
12 questions
Understanding the Fourth of July
Quiz
•
9th Grade
15 questions
Soccer World Cup Quiz Questions
Quiz
•
7th Grade