0% found this document useful (0 votes)
134 views

Advanced SQL Presentation Template

The document provides an overview of relational databases and SQL. It discusses key concepts like what an RDBMS is and the different types of SQL statements. It also covers topics like joins, constraints, and using MySQL Workbench for visual database modeling and administration.

Uploaded by

amit kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
134 views

Advanced SQL Presentation Template

The document provides an overview of relational databases and SQL. It discusses key concepts like what an RDBMS is and the different types of SQL statements. It also covers topics like joins, constraints, and using MySQL Workbench for visual database modeling and administration.

Uploaded by

amit kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 29

#LifeKoKaroLift

Advanced SQL – Session 1

11/03/2021
Lecture On : Advanced SQL
Edit Master text styles
Instructor : Edwin R. Das

11/03/2021 2
Today’s Agenda

1 What is an RDBMS? Review of key concepts


2 Using MySQL Workbench
3 Types of keys – Primary, Unique and Foreign keys
4 Cascading and referential integrity

11/03/2021 3
Data Science Certification
Databases – An Overview

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.

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


11/03/2021 4
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.


11/03/2021 5
SQL Statements

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:


Your mentor will share career advice and can help expand your professional network.
GRANT, REVOKE

Transaction Control Language (TCL) Statements:


COMMIT, ROLLBACK, SAVEPOINT
11/03/2021 6
Joins

Inner Join Outer Join

Only common data from both tables All data from both tables

Left Outer Join Right Outer Join

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. UPDATE and INSERT work in the same way

2. UPDATE modifies existing records while INSERT adds


new records
Practice in teams of 4 students
3. UPDATE adds new columnsIndustry
whileexpert
INSERT adds
mentoring new
to learn better
rows Get personalised feedback for improvements

4. None of the above


11/03/2021
11/3/21 Footer 11 10
Click to add Title
Poll 2(Answer)
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
Practice in teams of 4 students
3. UPDATE adds new columnsIndustry
whileexpert
INSERT adds
mentoring new
to learn better
rows Get personalised feedback for improvements

4. None of the above


11/03/2021
11/3/21 Footer 11 11
Click to add Title
Poll 3
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
Practice in teams of 4 students
Industry expert mentoring
3. DROP deletes table while TRUNCATE to learn better
only deletes
Get personalised feedback for improvements
records but keeps table structure

4. None of the above


11/03/2021
11/3/21 Footer 11 12
Click to add Title
Poll 3(Answer)
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
Practice in teams of 4 students

3. DROP deletes table while Industry


TRUNCATEexpert mentoring to learn better
only deletes
Get personalised feedback for improvements
records but keeps table structure

4. None of the above


11/03/2021
11/3/21 Footer 11 13
Click to add Title
Poll 4
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 Practice in teams of 4 students


Industry expert mentoring to learn better
3. 20 Get personalised feedback for improvements

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

2. 800 Practice in teams of 4 students


Industry expert mentoring to learn better
3. 20 Get personalised feedback for improvements

4. 400
11/03/2021
11/3/21 Footer 11 15
MySQL Workbench

• 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.

11/03/2021 16
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
11/03/2021 Connections. 17
MySQL Workbench

• Enter the name of


Enter the name for
the connection here. the connection in
the ‘Connection
Name’ field.
• Use the default
values for the rest of
the fields.

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.

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

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.

• 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.

11/03/2021 22
Click to add Title
Poll 5
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


Practice in teams of 4 students
Industry expert mentoring to learn better
Get personalised feedback for improvements
4. A foreign key cannot be composite

11/03/2021
11/3/21 Footer 11 23
Click to add Title
Poll 5(Answer)
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


Practice in teams of 4 students
Industry expert mentoring to learn better
Get personalised feedback for improvements
4. A foreign key cannot be composite

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

3. One cannot delete a row inIndustry expert mentoring to learn better


the child table without deleting the corresponding
Get personalised feedback for improvements
row in the parent table

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

3. One cannot delete a row inIndustry expert mentoring to learn better


the child table without deleting the corresponding
Get personalised feedback for improvements
row in the parent table

4.
11/3/21
None of the above
11/03/2021 Footer 11 27
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.

11/03/2021 28
Data Science Certification
Next Class

SQL Functions

11/03/2021 29
Data Science Certification

You might also like