You are on page 1of 11

CS204: Database Systems

Lab # 5: Introduction to SQL

Objective:

 SQL with group by and having


 SQL with Sub queries and Joins, More Control commands
 SQL DDL commands and script writing
 Sun MySQL DBMS (Ref. file “Getting started with MySQL.doc”)

Scope:
The student should know the following:
Understanding the complex logic

Useful Concepts :
FUNCTIONS: COUNT, MAX, MIN, AVG, SUM etc.
Display single aggregate record.

Data Types used in DDL command

CHAR for fixed length data such as Ids CHAR(9)


VARCHAR2 for variable length VARCHAR2(100)
NUMBER for integer or decimal numbers NUMBER(10), NUMBER(8,2)
DATE Date and Time DATE
CLOB Very large text CLOB

Ejaz Ahmed 1
Ejaz Ahmed 2
Ejaz Ahmed 3
Ejaz Ahmed 4
Outer Joins (Alternate solution for each query)

Ejaz Ahmed 5
Ejaz Ahmed 6
Exercises:
Ex. Display FirstName, Middle_names, FamilyName from Student table
Some names are two words, three words, four words.

Use Update SQL, to change salary of employee to 3500 who are from department SALES.

Similar exercises are same as in Lab-3

Additional examples:
for insert, delete and update use commit (DO)
rollback (UNDO)

update emp
set sal=1250
where ename='SMITH';

commit;

select * from emp;

update emp
set hiredate=to_date('12/11/1998','dd/mm/yyyy'),
sal=1300,
comm=250
where ename='SMITH';

insert into emp


(EMPNO,
ENAME,
JOB,
MGR,
HIREDATE,

Ejaz Ahmed 7
SAL,
COMM,
DEPTNO)
values(
5544,
'Usman',
'CLERK',
7839,
to_date('24/12/2009','dd/mm/yyyy'),
4500,
null,
20
);
commit;
delete from emp
where empno=5544;
commit;

NEXT PAGE

Ejaz Ahmed 8
Ejaz Ahmed 9
Ejaz Ahmed 10
Add more valid CHECK constraints in this script.

Evaluation:
Your Lab Work grade will depend on your active participation, individual efforts in solving Lab
Problem (script exercise) and Seriousness during the lab.

Exercise completion will be a part of evaluation.

Ejaz Ahmed 11

You might also like