DBMS SQL Commands CH 7
DBMS SQL Commands CH 7
Introduction
DDL Commands
DML Commands
SQL Statements, Operators, Clauses
Aggregate Functions
11/30/22
Table
Ch-7,SQL.......by Atnafu 7.6 pg.164 7
SQL: ALTER TABLE Statement
To add or drop columns on existing tables.
ALTER TABLE statement syntax:
ALTER TABLE <table name>
ADD attr datatype;
or
DROP COLUMN attr;
FoodCart
date food sold
date food sold 02/25/08 pizza 350
02/25/08 pizza 350 02/26/08 hotdog 500
02/26/08
11/30/22
hotdog 500Ch-7,SQL.......by 02/26/08
Atnafu
pizza 70 12
SQL: UPDATE Statement
To update the content of the table:
UPDATE statement syntax:
UPDATE <table name> SET <attr> = <value>
WHERE <selection condition>;
Example: UPDATE FoodCart SET sold = 349
WHERE date = ’02/25/08’ AND food = ‘pizza’;
FoodCart
SQL Statements:
Select
SQL Operations:
Join
Left Join
Right Join
Like
SQL Clauses:
Order By
Group By
Having
11/30/22 Ch-7,SQL.......by Atnafu 15
SQL: SELECT Statement
11/30/22
80 Ch-7,SQL.......by Atnafu 18
SQL: Join operation
A join can be specified in the FROM clause
which list the two input relations and the
WHERE clause which lists the join condition.
Example:
Emp Dept
ID State ID Division
1000 CA 1001 IT
1001 MA 1002 Sales
1002 TN 1003 Biotech
11/30/22 Ch-7,SQL.......by Atnafu 19
SQL: Join operation (cont.)
inner join = join
SELECT *
FROM emp join dept (or FROM emp, dept)
on emp.id = dept.id;
COUNT(attr)
SUM(attr)
MAX(attr)
MIN(attr)
AVG(attr)