Advanced SQL Presentation Template
Advanced SQL Presentation Template
11/03/2021
Lecture On : Advanced SQL
Edit Master text styles
Instructor : Edwin R. Das
11/03/2021 2
Today’s Agenda
11/03/2021 3
Data Science Certification
Databases – An Overview
What is a RDBMS?
• SQL statements allows one to express complex queries using a very simple language.
Only common data from both tables All data from both tables
All rows from left table, only matching from All rows from right table, only matching ones
right from left
11/03/2021 7
Click to add Title
Poll 1
Which of the following statements is used to fetch data
from database table?
1. INSERT
2. UPDATE
Practice in teams of 4 students
3. SELECT Industry expert mentoring to learn better
Get personalised feedback for improvements
4. FETCH
11/03/2021
11/3/21 Footer 11 8
Click to add Title
Poll 1(Answer)
Which of the following statements is used to fetch data
from database table?
1. INSERT
2. UPDATE
Practice in teams of 4 students
3. SELECT Industry expert mentoring to learn better
Get personalised feedback for improvements
4. FETCH
11/03/2021
11/3/21 Footer 11 9
Click to add Title
Poll 2
What is the main difference between UPDATE and INSERT?
1. 40
4. 400
11/03/2021
11/3/21 Footer 11 14
Click to add Title
Poll 4(Answer)
If Table A has 40 rows and Table B has 20 rows and both the
tables are combined using a CROSS join, how many rows
will the result set have:
1. 40
4. 400
11/03/2021
11/3/21 Footer 11 15
MySQL Workbench
11/03/2021 16
MySQL Workbench
11/03/2021 18
MySQL Workbench
Existing Databases
Editor
Output
11/03/2021 19
Constraints
Constraints are rules or conditions for the data in a table. Constraints may be at the
column level or table level. The following are common constraints in MySQL.
11/03/2021 20
KEYS
Keys are used to maintain referential integrity in a database. Keys are also indexes for a
table in MySQL. Indexes speed up data retrieval from database tables.
PRIMARY KEY – A unique identifier for each row in a table. Eg: Student Id, Employee
Code, etc. It can also be a combination of multiple columns. In this case it is also know as
a composite key.
UNIQUE KEY – A column which allows only unique values. Eg: Phone number, email
id, etc.
FOREIGN KEY - A column that references the primary key of another table. Primarily
used to maintain referential integrity
11/03/2021 21
Cascading
• Foreign keys are not just used to refer to the primary key of another table.
• It is also used to control delete and update actions on the table which contains the
primary key.
• When implemented, any changes made to the table containing the primary key will
also correspondingly DELETE or UPDATE the same on any foreign keys
referencing that table.
11/03/2021 22
Click to add Title
Poll 5
Which of following are true?
11/03/2021
11/3/21 Footer 11 23
Click to add Title
Poll 5(Answer)
Which of following are true?
11/03/2021
11/3/21 Footer 11 24
Click to add Title
Poll 6
Which of the following constraints provides a value in column even if no value
is entered by the user?
1. CHECK
2. DEFAULT
Practice in teams of 4 students
3. UNIQUE Industry expert mentoring to learn better
Get personalised feedback for improvements
4. NOT NULL
11/03/2021
11/3/21 Footer 11 25
Click to add Title
Poll 7
Cascading delete implies that:
1. Deleting a row in the parent table will also delete the corresponding row in the
child table
2. Deleting a row in the child table will also delete the corresponding row in the
parent table
Practice in teams of 4 students
4.
11/3/21
None of the above
11/03/2021 Footer 11 26
Click to add Title
Poll 7
Cascading delete implies that:
1. Deleting a row in the parent table will also delete the corresponding row in the
child table
2. Deleting a row in the child table will also delete the corresponding row in the
parent table
Practice in teams of 4 students
4.
11/3/21
None of the above
11/03/2021 Footer 11 27
Key Takeaway
11/03/2021 28
Data Science Certification
Next Class
SQL Functions
11/03/2021 29
Data Science Certification