Lecture-2 Fundamentals of RDB - Basic SQL
Lecture-2 Fundamentals of RDB - Basic SQL
Introduction to
Databases
Fundamentals of Relational Databases
Basic SQL
Lecturer- Salma Zalkha
• What is SQL
• Basic SQL:
• Create
• Insert
• Select From
Overvie • Where
• Update
w • Alter
• Delete
• Data Types
• Basic Queries
What is SQL?
• SQL is a standard language for • CREATE
accessing and manipulating • READ
databases. • UPDATE
• SQL stands for Structured Query • DELETE (DESTROY)
Language
• Lets you access and manipulate
databases
• Retrieving data from a database table
• Inserting data in a database table
CRUD
• Updating data in a database table
• Deleting data in a database table
• Creating new tables in a database
and many more
• SqLiteonline.com
• Create a table called (customers) with the customer_id first_name last_name age country
fields names: 1 John Doe 31 USA
• customer_id
2 Robert Luna 22 UAE
• first_name
3 David Robinson 22 UK
• last_name
• Age 4 John Reinhardt 25 UK
• country 5 Betty Doe 28 UAE
• Insert some values inside it.
• View the content of this table and some
the fields on this table that meet specific
criteria
Create a Table:
OR
Filter and Extract only those records that fulfill a specified condition
……
Alter table
ALTER TABLE table_name ADD column_name datatype; Add Column
1 keyboard 250 25
2 mouse 175 22
7 headphone 150 20
Problems to slove
Suppose a database has a table named Products with the following data:
Task: Select the names and prices of all the products from the Products table.
id name price quantity
1 keyboard 250 25
2 mouse 175 22
7 headphone 150 20
name price
keyboard 250
mouse 175
headphone 150
• Select the name and price columns for products whose quantity is less than
25.
• Select all the columns from the Products table for products
whose quantity is not equal to 25.
• Select all the columns from the Customers table for customers
whose country is not the UK.
• Select all the columns from the Products table for products whose quantity
is not equal to 25 and price is greater than 160.
• Select the name column from the Products table for products whose
quantity is equal to 25 or price is less than 160
• Select the name column from the Products table for products whose
quantity is not equal to 25 using the NOT operator.