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

Lecture-2 Fundamentals of RDB - Basic SQL

This document provides an introduction to databases and SQL. It defines SQL and its uses, and covers key SQL commands like CREATE, SELECT, UPDATE, DELETE and ALTER. Examples are given to demonstrate how to create tables and insert, select, update and delete data from the tables using SQL.

Uploaded by

sesaza52
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views

Lecture-2 Fundamentals of RDB - Basic SQL

This document provides an introduction to databases and SQL. It defines SQL and its uses, and covers key SQL commands like CREATE, SELECT, UPDATE, DELETE and ALTER. Examples are given to demonstrate how to create tables and insert, select, update and delete data from the tables using SQL.

Uploaded by

sesaza52
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Unit 4

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

• Visit the above link and let us create


something, with the help of SQL
documentation on W3SCHOOLS

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

CREATE TABLE table_name (


column1 datatype,
column2 datatype,
column3 datatype,
....
);
Insert into
INSERT INTO table_name (column1, column2,
column3, ...)
VALUES (value1, value2, value3, ...);

INSERT INTO table_name


VALUES (value1, value2, value3, ...);
Select - From / Where
SELECT column1, column2, ... FROM table_name;

OR

SELECT * FROM table_name;

Filter and Extract only those records that fulfill a specified condition

SELECT column1, column2, ... FROM table_name


WHERE condition;
Update
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;

……
Alter table
ALTER TABLE table_name ADD column_name datatype; Add Column

ALTER TABLE table_name DROP COLUMN column_name; Delete Column

ALTER TABLE table_name


RENAME COLUMN old_name to new_name; Rename column

ALTER TABLE table_name ALTER COLUMN column_name


datatype;
Change Column data
type
Delete
DELETE FROM table_name WHERE condition;

The WHERE clause specifies which record(s) should be deleted.


If you omit the WHERE clause, all records in the table will be deleted!

DROP TABLE table_name; Delete a table


Data Types
• Numeric Types
• BIT
• INT, INTEGER
• FLOAT/ DOUBLE
• Character and String Types
• CHAR Read more about Data Types


VARCHAR
TEXT
HERE
• TINYTEXT
• Date and Time
• DATE
• DATETIME / TIMESTAMP
• Boolean
And much more
• Now create another table with SQL called products, where we will
store all our products

id name price quantity

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.

You might also like