Lab 04
Lab 04
1
1 SQL
SQL Introduction
Introduction
2
2 What
What is
is aa Table?
Table?
3
3 Select
4
Select Statement
4 DDL
DDL
Statement
SQL
5
5 DML
DML
SQL Introduction
SQL stands for Structured Query Language.
Flagstaff Arizona 88 69
Albuquerque Mexico 80 72
Basic Select Statement
Select Statement
SELECT *
FROM <Table Name>
WHERE <Condition>
SELECT column-list
FROM table-names
WHERE condition(s)
A Basic SQL Select Statement
Performs 2 Types of Operations
Projection
SELECT column-list
FROM tables-names
WHERE condition(s)
Selection
Performing Projection
DDL
Data Definition Language
DML
Data Manipulation Language
DCL
Data Contol Language
DDL – Data Definition Language
Create Statement:
Using Create statement, we can create a new
table in the database. The syntax of the Create
statement is as follows.
Syntax:
CREATE TABLE <Table Name>
(Column 1 data type,
Column 2 data type,
Column 3 data type …
Column n data type);
DDL – Data Definition Language - Contd
Here, CREATE and TABLE are keywords.
Renaming a column
DDL – Data Definition Language - Contd
Syntax:
ALTER TABLE <Table name>
ADD(column 1 data type, column 2 data type, …
column n data type);
Renaming a column:
The syntax for renaming a column is as follows.
Syntax:
ALTER TABLE <Table name> RENAME COLUMN
<old name> TO <new name>;
Drop Statement:
Syntax:
Example:
Insert Statement:
Example:
Update Statement:
The update statement is used to update or change
records that match specified criteria. This is
accomplished by using a WHERE clause.
Syntax:
UPDATE <Table Name>
SET column 1 = value 1, column 2 = value 2, …
column 3 = value 3
WHERE <condition>;
DML – Data Manipulation Language- Contd
Example:
UPDATE employee
SET age = age + 1
WHERE last = kumar;
Syntax:
DELETE FROM <Table Name>
WHERE <Condition>
Example: