Fundamentals of Database Systems: (SQL - I)
Fundamentals of Database Systems: (SQL - I)
Malay Bhattacharyya
Assistant Professor
1 Preliminaries
2 Data Definition
Principle Structure
Database Creation
Database Modification
3 Problems
Outline Preliminaries Data Definition Problems
Basics of SQL
SQL is not only for querying, rather it also helps in defining the
structure of the data, modifying the data and specifying the
security constraints.
Outline Preliminaries Data Definition Problems
Basics of SQL
SQL is not only for querying, rather it also helps in defining the
structure of the data, modifying the data and specifying the
security constraints.
SQL functionalities
History
“An SQL query goes into a bar, walks up to two tables and asks,
‘May I join you?’.” – Anonymous.
History
“An SQL query goes into a bar, walks up to two tables and asks,
‘May I join you?’.” – Anonymous.
History
“An SQL query goes into a bar, walks up to two tables and asks,
‘May I join you?’.” – Anonymous.
History
“An SQL query goes into a bar, walks up to two tables and asks,
‘May I join you?’.” – Anonymous.
History
“An SQL query goes into a bar, walks up to two tables and asks,
‘May I join you?’.” – Anonymous.
History
“An SQL query goes into a bar, walks up to two tables and asks,
‘May I join you?’.” – Anonymous.
databases
/ / \ \
Note: In Oracle SQL, scott and tiger are the general username
and password, respectively. The default password for the DBA is
system.
Outline Preliminaries Data Definition Problems
Note: Total number of digits (before and after the decimal point) and number
of digits only after the decimal point are specified by dig and dec, respectively.
Outline Preliminaries Data Definition Problems
Note: A string can contain letters, numbers, and special characters. The
maximum number of characters in a string can be specified with size.
Outline Preliminaries Data Definition Problems
Consider a table
Table: IPL
YEAR VENUE WINNER PoS
8 India Rajasthan Royals Shane Watson
9 South Africa Deccan Chargers Adam Gilchrist
10 India Chennai Super Kings Sachin Tendulkar
11 India Chennai Super Kings Chris Gayle
12 India Kolkata Knight Riders Sunil Narine
13 India Mumbai Indians Shane Watson
14 India, UAE Kolkata Knight Riders Glenn Maxwell
15 India Mumbai Indians Andre Russell
16 India Sunrisers Hyderabad Virat Kohli
17 India Mumbai Indians Ben Stokes
18 India Chennai Super Kings Sunil Narine
19 India Mumbai Indians Andre Russell
20 UAE Mumbai Indians Jofra Archer
Outline Preliminaries Data Definition Problems
Creating a table
Deleting a table
The IPL table can be deleted from database using the following
SQL query.
Altering a table
Altering a table
Altering a table
The IPL table and its attributes can be renamed and reused, as
and when required, within an SQL query as follows:
The IPL table and its attributes can be renamed and reused, as
and when required, within an SQL query as follows:
This will yield the names of Player of Series (PoS) winners who
once won earlier and for ‘Mumbai Indians’ at a later time.
Outline Preliminaries Data Definition Problems
Note: It works on the entire tuple and can not delete values on
arbitrary attributes.
Outline Preliminaries Data Definition Problems
Table: IPL
YEAR VENUE WINNER PoS
10 India Chennai Super Kings Sachin Tendulkar
11 India Chennai Super Kings Chris Gayle
12 India Kolkata Knight Riders Sunil Narine
13 India Mumbai Indians Shane Watson
14 India, UAE Kolkata Knight Riders Glenn Maxwell
15 India Mumbai Indians Andre Russell
16 India Sunrisers Hyderabad Virat Kohli
17 India Mumbai Indians Ben Stokes
18 India Chennai Super Kings Sunil Narine
19 India Mumbai Indians Andre Russell
20 UAE Mumbai Indians Jofra Archer
Outline Preliminaries Data Definition Problems
Insert operation
Insert operation
Table: IPL
YEAR VENUE WINNER PoS
8 India Rajasthan Royals Shane Watson
9 South Africa Deccan Chargers Adam Gilchrist
10 India Chennai Super Kings Sachin Tendulkar
11 India Chennai Super Kings Chris Gayle
12 India Kolkata Knight Riders Sunil Narine
13 India Mumbai Indians Shane Watson
14 India, UAE Kolkata Knight Riders Glenn Maxwell
15 India Mumbai Indians Andre Russell
16 India Sunrisers Hyderabad Virat Kohli
17 India Mumbai Indians Ben Stokes
18 India Chennai Super Kings Sunil Narine
19 India Mumbai Indians Andre Russell
20 UAE Mumbai Indians Jofra Archer
Update operation
update IPL
set YEAR = YEAR + 2000
where YEAR < 2000;
Outline Preliminaries Data Definition Problems
Update operation
Table: IPL
YEAR VENUE WINNER PoS
2008 India Rajasthan Royals Shane Watson
2009 South Africa Deccan Chargers Adam Gilchrist
2010 India Chennai Super Kings Sachin Tendulkar
2011 India Chennai Super Kings Chris Gayle
2012 India Kolkata Knight Riders Sunil Narine
2013 India Mumbai Indians Shane Watson
2014 India, UAE Kolkata Knight Riders Glenn Maxwell
2015 India Mumbai Indians Andre Russell
2016 India Sunrisers Hyderabad Virat Kohli
2017 India Mumbai Indians Ben Stokes
2018 India Chennai Super Kings Sunil Narine
2019 India Mumbai Indians Andre Russell
2020 UAE Mumbai Indians Jofra Archer
Outline Preliminaries Data Definition Problems
Problems