Advanced DBMS – Practical Exercise 4
Exercise 4 Joins
Consider the following database of student enrollment in courses &
books adopted for each course:
STUDENT (regno: string, name: string, major: string, bdate:date)
COURSE (course #:int, cname:string, dept:string)
ENROLL ( regno:string, course#:int, sem:int, marks:int)
BOOK _ ADOPTION (course# :int, sem:int, book-ISBN:int)
TEXT (book-ISBN:int, book-title:string, publisher:string,
author:string)
Demonstrate with appropriate SQL Statement for the following:
1. Create the above tables by properly specifying the primary keys
and the foreign keys.
2. Enter at least five tuples for each relation.
3. Demonstrate how you add a new text book to the database and
make this book be adopted by some department.
4. List the students who have been enrolled.
5. List the students who have registered but not enrolled.
6. List the books which have been adopted.
7. List any department that has all its adopted books published by a
specific publisher.
8. Illustrate inner join, Left join, right join, full join by joining
STUDENT and ENROLL table.
Objective:
The objective of this exercise is to enable you to understand and use SQL
relational concepts along with the concepts of Joins.
Procedure and description:
By getting the knowledge of Primary Key and Foreign Key the relationship
between two tables can be matched and developed. There are 3 types of
relations between tables – One-To-Many, Many-To-Many and One-To-One.
Manipal University Jaipur B2101 Page No.: 8
Advanced DBMS – Practical Exercise 4
We use the process called Normalization for removing redundant data
between tables when the relations are built.
SQL joins are used to query data from two or more tables, based on a
relationship between certain columns in these tables. The INNER JOIN
keyword return rows when there is at least one match in both tables (say
table_name1 & table_name2). The LEFT JOIN keyword returns all rows
from the left table (table_name1) even if there are no matches in the right
table (table_name2). The RIGHT JOIN keyword returns all the rows from
the right table (table_name2), even if there are no matches in the left table.
The FULL JOIN keyword return rows when there is a match in one of the
tables.
Algorithm: The steps for this exercise are given below:
Step – 1: Start
Step – 2: Create Database, tables using CREATE commands with its
essential attributes.
Step – 3: Insert the values using INSERT INTO statements. (Insert the
suitable values (tuples) so that queries are executed correctly.)
Step – 4: Execute different Commands and extract information from the
table. (Hint: use commands like FROM, WHERE, DISTINCT,
INNER JOIN, LEFT JOIN, RIGHT JOIN, FULL JOIN, GROUP
BY, ORDERBY etc. You can use suitable operators like AND &
OR for certain conditions to meet)
Expected Output: Creation of tables, use of normalization and its
modification through SQL commands.
Manipal University Jaipur B2101 Page No.: 9