100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Class notes

concept of sql

Rating
-
Sold
-
Pages
16
Uploaded on
13-08-2024
Written in
2024/2025

it gives a detail of sql

Institution
Course










Whoops! We can’t load your doc right now. Try again or contact support.

Connected book

Written for

Course

Document information

Uploaded on
August 13, 2024
Number of pages
16
Written in
2024/2025
Type
Class notes
Professor(s)
Abraham silberschatz, henry f. korth, s. sudharsha
Contains
All classes

Subjects

Content preview

Outline

 Join Expressions
 Views
 Transactions
 Integrity Constraints
 SQL Data Types and Schemas
 Index Definition in SQL
Chapter 4 : Intermediate SQL  Authorization




Database System Concepts, 7th Ed.


LICET, CSE 4.2 ©Silberschatz, Korth, Sudarshan and GK




Joined Relations Natural Join in SQL

 Join operations take two relations and return as a result another  Natural join matches tuples with the same values for all common
attributes, and retains only one copy of each common column.
relation.
 A join operation is a Cartesian product which requires that tuples in the  List the names of instructors along with the course ID of the courses that
they taught
two relations match (under some condition). It also specifies the
attributes that are present in the result of the join • select name, course_id
from students, takes
 The join operations are typically used as subquery expressions in the
where student.ID = takes.ID;
from clause
 Three types of joins:  Same query in SQL with “natural join” construct
• Natural join • select name, course_id
from student natural join takes;
• Inner join
• Outer join




LICET, CSE 4.3 ©Silberschatz, Korth, Sudarshan and GK LICET, CSE 4.4 ©Silberschatz, Korth, Sudarshan and GK

, Natural Join in SQL (Cont.) Student Relation

 The from clause can have multiple relations combined using natural join:
select A1, A2, … An
from r1 natural join r2 natural join .. natural join rn
where P ;




LICET, CSE 4.5 ©Silberschatz, Korth, Sudarshan and GK LICET, CSE 4.6 ©Silberschatz, Korth, Sudarshan and GK




Takes Relation student natural join takes




LICET, CSE 4.7 ©Silberschatz, Korth, Sudarshan and GK LICET, CSE 4.8 ©Silberschatz, Korth, Sudarshan and GK

, Dangerous in Natural Join Natural Join with Using Clause

 Beware of unrelated attributes with same name which get equated  To avoid the danger of equating attributes erroneously, we can use the
incorrectly “using” construct that allows us to specify exactly which columns should be
 Example -- List the names of students instructors along with the titles of equated.
courses that they have taken  Query example
• Correct version select name, title
select name, title from (student natural join takes) join course using (course_id)
from student natural join takes, course
where takes.course_id = course.course_id;
• Incorrect version
select name, title
from student natural join takes natural join course;
 This query omits all (student name, course title) pairs where the
student takes a course in a department other than the student's
own department.
 The correct version (above), correctly outputs such pairs.




LICET, CSE 4.9 ©Silberschatz, Korth, Sudarshan and GK LICET, CSE 4.10 ©Silberschatz, Korth, Sudarshan and GK




Join Condition Join Condition (Cont.)

 The on condition allows a general predicate over the relations being  The on condition allows a general predicate over the relations being
joined joined.
 This predicate is written like a where clause predicate except for the use  This predicate is written like a where clause predicate except for the use
of the keyword on of the keyword on.
 Query example  Query example
select * select *
from student join takes on student_ID = takes_ID from student join takes on student_ID = takes_ID
• The on condition above specifies that a tuple from student matches a • The on condition above specifies that a tuple from student matches a
tuple from takes if their ID values are equal. tuple from takes if their ID values are equal.
 Equivalent to:  Equivalent to:
select * select *
from student , takes from student , takes
where student_ID = takes_ID where student_ID = takes_ID




LICET, CSE 4.11 ©Silberschatz, Korth, Sudarshan and GK LICET, CSE 4.12 ©Silberschatz, Korth, Sudarshan and GK
$2.99
Get access to the full document:

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached

Get to know the seller
Seller avatar
sathishelumalaie67

Get to know the seller

Seller avatar
sathishelumalaie67 Loyola-icam college of engineering and technology
Follow You need to be logged in order to follow users or courses
Sold
0
Member since
1 year
Number of followers
0
Documents
10
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions