This document summarizes an advanced SQL training session that covered:
1. An overview of relational databases and MySQL as an RDBMS tool.
2. How MySQL Workbench can be used to visually design databases.
3. Key concepts like constraints, keys, and cascading that help maintain data integrity.
Constraints impose restrictions on data, keys are used for indexing and integrity, and cascading automatically propagates changes between linked tables.
2. Edit Master text styles
Edit Master text styles
26-02-2023 2
Lecture On : Advanced
SQL
Instructor : Edwin R. Das
3. 26-02-2023 3
Today’s Agenda
What is an RDBMS? Review of key concepts
Using MySQL Workbench
Cascading and referential integrity
Types of keys – Primary, Unique and Foreign keys
Data Science Certification
4. 26-02-2023
What is a Relational Database?
• A collection of inter-related data.
• It is organised in the form of schema, tables and views.
• It is efficient to retrieve, insert and delete data from a database.
4
Databases – An Overview
What is a RDBMS?
• It is a software that is used to manage a database.
• It helps in the following:
• Defining the way in which data is organised
• Updating and retrieving data
• User access management
5. SQL Statements
Structured Query Language (SQL):
• It is a way to communicate with database.
• All operations on a database are performed through SQL statements.
• Queries to the database can be expressed using logical statements.
• SQL statements allows one to express complex queries using a very simple language.
• It is very easy to read and comprehend for humans.
26-02-2023 5
6. Your mentor will share career advice and can help expand your professional network.
6
SQL Statements
26-02-2023 6
Data Definition Language (DDL) Statements:
ALTER, CREATE, DROP, RENAME, TRUNCATE
Data Manipulation Language (DML) Statements:
SELECT, UPDATE, DELETE, ALTER, INSERT
Data Control Language (DCL) Statements:
GRANT, REVOKE
Transaction Control Language (TCL) Statements:
COMMIT, ROLLBACK, SAVEPOINT
7. Inner Join
Only common data from both tables
7
Joins
26-02-2023
Outer Join
All data from both tables
Left Outer Join
All rows from left table, only matching from right
Right Outer Join
All rows from right table, only matching ones from left
8. Click to add Title
26-02-2023 Footer
Practice in teams of 4 students
Industry expert mentoring to learn better
Get personalised feedback for improvements
8
Poll 1
26-02-2023 11
Which of the following statements is used to fetch data
from database table?
1. INSERT
2. UPDATE
3. SELECT
4. FETCH
9. Click to add Title
26-02-2023 Footer
Practice in teams of 4 students
Industry expert mentoring to learn better
Get personalised feedback for improvements
9
Poll 1(Answer)
26-02-2023 11
Which of the following statements is used to fetch data
from database table?
1. INSERT
2. UPDATE
3. SELECT
4. FETCH
10. Click to add Title
26-02-2023 Footer
Practice in teams of 4 students
Industry expert mentoring to learn better
Get personalised feedback for improvements
10
Poll 2
26-02-2023 11
What is the main difference between UPDATE and INSERT?
1. UPDATE and INSERT work in the same way
2. UPDATE modifies existing records while INSERT adds
new records
3. UPDATE adds new columns while INSERT adds new
rows
4. None of the above
11. Click to add Title
26-02-2023 Footer
Practice in teams of 4 students
Industry expert mentoring to learn better
Get personalised feedback for improvements
11
Poll 2(Answer)
26-02-2023 11
What is the main difference between UPDATE and INSERT?
1. UPDATE and INSERT work in the same way
2. UPDATE modifies existing records while INSERT adds
new records
3. UPDATE adds new columns while INSERT adds new
rows
4. None of the above
12. Click to add Title
26-02-2023 Footer
Practice in teams of 4 students
Industry expert mentoring to learn better
Get personalised feedback for improvements
12
Poll 3
26-02-2023 11
What is the difference between DROP and TRUNCATE?
1. DROP deletes the table but TRUNCATE is not a valid SQL
statement
2. TRUNCATE deletes table while DROP only deletes
records but keeps table structure
3. DROP deletes table while TRUNCATE only deletes
records but keeps table structure
4. None of the above
13. Click to add Title
26-02-2023 Footer
Practice in teams of 4 students
Industry expert mentoring to learn better
Get personalised feedback for improvements
13
Poll 3(Answer)
26-02-2023 11
What is the difference between DROP and TRUNCATE?
1. DROP deletes the table but TRUNCATE is not a valid SQL
statement
2. TRUNCATE deletes table while DROP only deletes
records but keeps table structure
3. DROP deletes table while TRUNCATE only deletes
records but keeps table structure
4. None of the above
14. Click to add Title
26-02-2023 Footer
Practice in teams of 4 students
Industry expert mentoring to learn better
Get personalised feedback for improvements
14
Poll 4
26-02-2023 11
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
2. 800
3. 20
4. 400
15. Click to add Title
26-02-2023 Footer
Practice in teams of 4 students
Industry expert mentoring to learn better
Get personalised feedback for improvements
15
Poll 4(Answer)
26-02-2023 11
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
2. 800
3. 20
4. 400
16. 26-02-2023 16
• MySQL is a relational database management system.
• MySQL workbench is a visual database design and modelling access tool.
• It is useful for creating a visual model of a database which can be easily
translated into a database.
• It has a in built sql editor which can be used to create and query MySQL
server databases.
• The data can be exported easily to commonly used formats.
• Using tabs, one can work on multiple databases at a time.
• It is also an administration tool which can be used for user access control,
backup and restore and configuring the MySQL server.
MySQL Workbench
17. 26-02-2023 17
MySQL Workbench
• This the first screen
you see when
opening MySQL
Workbench.
• The first step would
be to create a
connection by
clicking on the ‘+’
sign next to MySQL
Connections.
18. 26-02-2023 18
MySQL Workbench
• Enter the name of
the connection in
the ‘Connection
Name’ field.
• Use the default
values for the rest
of the fields.
Enter the name for
the connection here.
20. 26-02-2023 20
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.
NOT NULL - Ensures that a column cannot have null values
UNIQUE - Ensures that all values in a column are distinct
PRIMARY KEY - A column that uniquely identifies each row in a table
FOREIGN KEY - A column that references the primary key of another table
CHECK - Imposes specific conditions on a column
DEFAULT - Sets a default value for a column if unspecified
INDEX - A column can be set as an index. Used to speed up data retrieval
Constraints
21. 26-02-2023 21
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
KEYS
22. 26-02-2023 22
• 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.
• This helps in maintaining referential integrity.
• 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.
Cascading
23. Click to add Title
26-02-2023 Footer
Practice in teams of 4 students
Industry expert mentoring to learn better
Get personalised feedback for improvements
23
Poll 5
26-02-2023 11
Which of following are true?
1. Primary keys cannot have null values
2. Foreign Keys can have duplicate values
3. Unique keys cannot have null values
4. A foreign key cannot be composite
24. Click to add Title
26-02-2023 Footer
Practice in teams of 4 students
Industry expert mentoring to learn better
Get personalised feedback for improvements
24
Poll 5(Answer)
26-02-2023 11
Which of following are true?
1. Primary keys cannot have null values
2. Foreign Keys can have duplicate values
3. Unique keys cannot have null values
4. A foreign key cannot be composite
25. Click to add Title
26-02-2023 Footer
Practice in teams of 4 students
Industry expert mentoring to learn better
Get personalised feedback for improvements
25
Poll 6
26-02-2023 11
Which of the following constraints provides a value in column even if no value
is entered by the user?
1. CHECK
2. DEFAULT
3. UNIQUE
4. NOT NULL
26. Click to add Title
26-02-2023 Footer
Practice in teams of 4 students
Industry expert mentoring to learn better
Get personalised feedback for improvements
26
Poll 7
26-02-2023 11
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
3. One cannot delete a row in the child table without deleting the corresponding
row in the parent table
4. None of the above
27. Click to add Title
26-02-2023 Footer
Practice in teams of 4 students
Industry expert mentoring to learn better
Get personalised feedback for improvements
27
Poll 7
26-02-2023 11
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
3. One cannot delete a row in the child table without deleting the corresponding
row in the parent table
4. None of the above
28. 26-02-2023 28
Key Takeaway
1. A relational database is a collection of inter related data.
2. MySQL is an RDBMS which is used to manage a database.
3. MySQL workbench is a software that can be used to design databases
visually.
4. Constraints impose restrictions on the data that can be entered into a
database.
5. Keys are indexes which can be used speed up data retrieval and
maintain referential integrity.
6. Cascading is a type of constraint that helps maintain referential
integrity with foreign keys.
Data Science Certification