You are on page 1of 6

CS204: Database Systems

Lab # 3: Introduction to SQL

Objective:
1-Database Login and sample schema
2-Introduction to SQL (DML, DDL, DCL)
3-SQL sample commands and interactions
4-Learning and practice
Scope:
The student should know the following:
 Login and work around SQL
 SQL Practice
 Basic exercises

Useful Concepts :
Command level programming experience
How to see source data as a table
Table name, its column name and column’s datatypes

Discussion:
DML, DDL, DCL

Control Commands are Set, column, format etc.

Login:
User id: stxxxxxxxxx
Password: oracle
Host string: (Database name)

(Use database name ora10g in Lab)

SQL>connect stxxxxxxxxx/oracle@ ora10g

SQL>connect scott/tiger@ora10g (test user)

SQL>show user

SQL>alter user stxxxxxxxxx identified by xyz;

For administrator database on your personal pc:


sys / as sysdba then press enter key and type your password that you have given during installation

select *
from tab;

no rows select message will appear.

This means your schema is empty.

To load sample tables with data, download file demobld.sql from my slate

Ejaz Ahmed 1
Save it at D-drive, unzip it and follow up as

SQL>@d:\demobld.sql

select *
from tab;

To list column names and their datatypes of a table EMP.


desc emp;

To list column names with data of a table EMP


Select *
From emp;

set linesize 100


set pagesize 50
set timing on
purge recyclebin

How to fix SQL Editor’s width as default:

Menu: OptionsEnvironmentBuffer width:1000 used for left-right scrolling

Ejaz Ahmed 2
Exercises:
desc dept

select dname, loc


from dept;

select ename, hiredate, job, comm, sal


from emp;

select distinct job


from emp;

select job
from emp;

Ejaz Ahmed 3
Ejaz Ahmed 4
select *
from emp
where ename like '_A%';

select *
from emp
where ename like '%A%';

select *
from emp
where ename NOT like '%A%';

select *
from emp
where comm IS NULL;

Ejaz Ahmed 5
select *
from emp
where comm = NULL; -- does not give you any output

Exercise and Logical Evaluation:

Q. display project number, project name and name of project manager number

Q. List of project number, employee number and duration of employee who works in project

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

Write a report that contains the following points:


Which methods are adopted using SQL?
Give alternate SQL for different logic or clauses.
Within the scope of this lecture, do you have any query which is not covered?

Ejaz Ahmed 6

You might also like