SQL Introduction
K M Tanvir
Lecturer, ISRT, University of Dhaka
Introduction to Database
A database is nothing more than a set of related information. A telephone book, for example, is a
database of the names, phone numbers, and addresses of all people living in a particular region.
While a telephone book is frequently used database, it suffers from the following:
❖ Finding a person’s telephone number can be time consuming, especially if the telephone book
contains a large number of entries (slow data retrieval rate).
❖ A telephone book is indexed only by last/first names, so finding the names of the people living at
a particular address, while possible in theory, is not a practical use for this database (limited
indexing capabilities).
❖ From the moment the telephone book is printed, the information becomes less and less accurate
as people move into or out of a region, change their telephone numbers, or move to another
location within the same region (outdated information).
Introduction to Database
❖ The same drawbacks attributed to telephone books can also apply to any manual data storage
system
❖ Because of the nature of paper databases, some of the first computer applications developed
were database systems, which are computerized data storage and retrieval mechanisms.
❖ Because a database system stores data electronically rather than on paper, a database system is
able to retrieve data more quickly, index data in multiple ways, and deliver up-to-the-minute
information to its user community.
❖ Modern database systems can manage petabytes of data, accessed by clusters of servers each
caching tens of gigabytes of that data in high-speed memory.
Relational Database
Student Table Customer Table
Product ID Product Name Price Customer ID Customer Name Contact Number City
1 Macbook Air 131000 105 Ariyan Ahmed 0123456789 Dhaka
2 Iphone 15 96000 106 Ramisa Alvina 0987654321 Sylhet
3 Airpod 31000 107 Efazul Haque 0111222333 Khulna
Order Table
Customer ID Product ID Order date Quantity
107 2 02/07/2024 5
105 3 04/07/2024 15
107 1 04/07/2024 5
106 2 05/07/2024 10
Relational Database
❖ Each table in a relational database includes information that uniquely identifies a row in that
table, known as the primary key, along with additional information needed to describe the entity
completely. Looking again at the product table, the Product ID column holds a different number
for each product; Macbook Air, for example, can be uniquely identified by product ID
1. No other product will ever be assigned that identifier, and no other information is needed to
locate Macbook Air’s data in the product table.
❖ A primary key consisting of two or more columns is known as a compound key. For example,
we might have chosen to use the combination of the name and date of birth columns as the
primary key which should be unique for our database.
Relational Database
❖ Some of the tables also include information used to navigate to another table. For example, the
order table includes a column called customer ID, which contains the unique identifier of the
customer from ”Customer Table”, along with a column called Product ID, which contains the
unique identifier of a product from “Product Table”.
❖ These columns are known as foreign keys which are used to create the relation between the
tables.
❖ If you are looking at a particular order record and want to know more information about the
customer who purchase the product, you would take the value of the Customer ID and use it to
find the appropriate row in the “Customer Table”.
What is SQL?
❖ SQL (Structured Query Language) is the standard programming language used to
communicate with and manage relational databases.
❖ It allows users to create, update, and retrieve data stored in database tables.
❖ Dr. Codd, a computer scientist at IBM, introduced the concept of relational databases in
1970.
❖ Following the idea, IBM designed a language called SEQUEL (Structured English Query
Language) to manage relational data.
❖ Later renamed SQL due to trademark issues.
Why Should We Learn SQL?
❖ SQL is used across all industries - finance, healthcare, telecom, e-commerce and
government.
❖ Behind most modern apps and websites is a database powered by SQL.
❖ If you are aiming to work in data science, business intelligence, or some other facet of data
analysis, you will need to know SQL, along with other languages such as Python and R.
❖ Data is everywhere, in huge quantities, and arriving at a rapid pace, and people who can extract
meaningful information from all this data are in big demand.
❖ SQL works with many relational database management systems (RDBMS) such as: MySQL,
PostgreSQL, Oracle, Microsoft SQL Server, SQLite.
What is MySQL?
❖ MySQL is an open-source Relational Database Management System (RDBMS) that uses SQL
to manage and interact with data.
❖ It was originally developed by MySQL AB and is now owned by Oracle Corporation.
❖ MySQL is freely available under the GNU General Public License, making it accessible for
learning, research, and start-ups.
❖ MySQL Workbench is A GUI tool for designing and querying databases.
SQL Syntax
❖ SQL is followed by a unique set of rules and guidelines called Syntax.
❖ All the SQL statements start with any of the keywords like SELECT, INSERT, UPDATE,
DELETE, ALTER, DROP, CREATE and all the statements end with a semicolon (;).
❖ The most important point to be noted here is that SQL is case insensitive, which means
SELECT and select have same meaning in SQL statements.
❖ Whereas, MySQL makes difference in table names. So, if you are working with MySQL, then
you need to give table names as they exist in the database.
Connect to ISRT Server
Give password: student-isrt
Practice
https://onecompiler.com/mysql
SQL Commands
SQL Commands