1. RDBMS LAB-1
Learning Objectives
Introduction to SQL
Concept of Table and Relation
Oracle Classification of SQL
Table Creation,Data Insertion,Data Retrieval,Table
Structure Modification,Data Deletion and Table
Deletion
Prepared by:
Akshaya Kumar Dash
Sasmita Mishra
Copyright@2012 Trident Academy of Technology 1
2. Structured Query Language(SQL)
SQL is a database computer language designed for the
retrieval and management of data in relational database.
SQL is structured Query Language which is a computer
language for storing, manipulating and retrieving data
stored in relational database.
SQL is the standard language for Relation Database
System. All relational database management systems
like MySQL, MS Access, Oracle, Sybase, Informix,
postgres and SQL Server uses SQL as standard database
language.
Copyright@2012 Trident Academy of Technology 2
3. Why SQL
•Allows users to access data in relational database
management Systems.
•Allow users to describe the data.
•Allow users to define data in database and manipulate
that data.
•Allow to embed within other languages using SQL
modules, libraries & pre-compilers.
•Allow users to create and drop databases and tables.
•Allow users to create view, stored procedure, functions
in a database.
•Allow users to set permissions on tables, procedures,
and views Copyright@2012 Trident Academy of Technology 3
4. Requirements to learn Oracle
SQL
A Computer with following
Softwares
OS:Windows or Linux
DB:Oracle 9i or any other Higher
version
Copyright@2012 Trident Academy of Technology 4
5. Books
Beginnig SQL by Paul Wilton
SQL Bible by Alex Kriegel
SQL for dummies
Head First SQL
SQL,PL/SQL The Programming Language of
Oracle by Ivan Bayross(Available in Library)
You need not a buy a single book(only Bikalp is
the lab classes or internet)
Copyright@2012 Trident Academy of Technology 5
6. Oracle has grouped the commands of SQL into the
following five sublanguages.
DDL(Data Definition Language):
Create,Alter,Drop,Rename,Truncate
DML(Data Manipulation Language)
Insert,Update,Delete
DQL(Data Query Language)
Select
DCL(Data Control Language)
Grant,Revoke
TCL(Transcation Control Language)
Rollback,Savepoint
Copyright@2012 Trident Academy of Technology 6
7. Relation and Tables
In relational database systems (DBS) data are
represented using tables (relations). A query
issued against the DBS also results in a table. A
table has the following structure:
Copyright@2012 Trident Academy of Technology 7
8. A table is uniquely identied by its name and
consists of rows that contain the stored
information, each row containing exactly one
tuple (or record).
A table can have one or more columns.
A column is made up of a column name and a
data type, and it describes an attribute of the
tuples. The structure of a table, also called
relation schema, thus is dened by its attributes.
The type of information to be stored in a table is
defined by the data types of the attributes at table
creation time.
Copyright@2012 Trident Academy of Technology 8
9. Oracle Data Types
char(n): Fixed-length character data (string), n characters long. The
maximum size for n is 255 bytes (2000 in Oracle8). Note that a string of
type char is always padded on right with blanks to full length of n.
Example: char(40)
varchar2(n): Variable-length character string. The maximum size for n is
2000 (4000 in Oracle8). Only the bytes used for a string require
storage.
Example: varchar2(80)
number(o, d): Numeric data type for integers and reals. o = overall
number of digits, d = number of digits to the right of the decimal point.
Maximum values: o =38, d= -84 to +127. Examples: number(8),
number(5,2)
Note that, e.g., number(5,2) cannot contain anything larger than 999.99
without resulting in an error. Data types derived from number are
int[eger], dec[imal], smallint and real.
date: Date data type for storing date and time.The default format for a
date is: DD-MMM-YY. Examples: Trident Academy of Technology
Copyright@2012 '13-OCT-94', '07-JAN-98' 9
11. Describe Command will Display the column
names and corressponding data types present in
the table.
describe table-name;
Desc table-name;
eg:
desc student
Copyright@2012 Trident Academy of Technology 11
12. Insert Command
It can be executed in the following three ways
Insert into table-name
values(value1,value2,....,valuen);
Insert into table-name (col1,col2,...,coln) values
(value1,value2,...,valuen);
Insert into table-name
values(&col1,&col2,...,&coln);
Copyright@2012 Trident Academy of Technology 12
13. View the content of table
SELECT STATEMENT Syntax:
SELECT col1,col2,col3,...,coln
FROM table-1,...,table-n
[WHERE condition]
[ORDER BY col1 [ASC|DESC] [, col2 [ASC|
DESC] ...]];
Copyright@2012 Trident Academy of Technology 13
14. SELECT CONTINUED...
The SELECT Clause lists the columns to display.
The FROM clause lists the tables from which to obtain
the data
The WHERE clause specifies the condition or
conditions that need to be satisfied by the rows of
the tables indicated in the FROM clause
The ORDER BY clause indicates the criterion or
criteria used to sort rows that satisfy WHERE clause
Copyright@2012 Trident Academy of Technology 14
15. Where Clause
The Conditions are of the following form
Column-name comparisonoperator single-value
Comparison Operators Description
= Equal to
<> Not equal to
< Less than
<= Less than or equal to
> Greater than
>= Greater than or equal to
Copyright@2012 Trident Academy of Technology 15
16. ALTER COMMAND
One can add a new column,drop an existing
column,modify the datatype of a column,and drop
the constraints using the following commands
respectively.
ALTER TABLE table_name ADD COLUMN_name datatype;
ALTER TABLE table_name DROP COLUMN column_name;
ALTER TABLE table_name MODIFY (column_name,datatype);
ALTER TABLE table_name DROP CONSTRAINT constraint_name;
Copyright@2012 Trident Academy of Technology 16
17. TRUNCATE COMMAND
TRUNCATE will remove all the rows of a table
TRUNCATE TABLE table-name;
Note:
We can't truncate the rows of a table if there are
referential integrity constraints for which this table
is parent table.
We can't roolback a TRUNCATE statement
Copyright@2012 Trident Academy of Technology 17
18. DROP COMMAND
DROP command will permanently delete the table
with all its data
DROP TABLE table-name [CASCADE
CONSTRAINT];
Copyright@2012 Trident Academy of Technology 18
19. Lab Assignment-1
Create the follwing tables
branch(branch_name,branch_city,assets)
customer(customer_name,customer_street,customer
_city)
loan(loan_number,branch_name,amount)
borrower(customer_name,loan_number)
account(account_number,branch_name,balance)
depositor(customer_name,account_number)
Copyright@2012 Trident Academy of Technology 19
20. Assignment Continued..
Populate the branch table with the following data
branch_name branch_city assets
Brighton Brooklyn 7100000
Downtown Brooklyn 9000000
Mianus Horseneck 400000
North Town Rye 3700000
Perryridge Horseneck 1700000
Pownal Bennington 300000
Redwood Palo Alto 2100000
Round Hill Horseneck 8000000
Copyright@2012 Trident Academy of Technology 20
21. Assignment Continued..
Populate the customer table with the following data
Customer_name Customer_street Customer_city
Adams Spring Pittsfield
Brooks Senator Brooklyn
Curry North Rye
Glenn Sand Hill Woodside
Green Walnut Stamford
Hayes Main Harrison
Johnson Alma Palo Alto
Jones Main Harrison
Lindsay Park Pittsfield
Smith North Rye
Turner Putnam Stamford
Williams Nassau Princeton
Copyright@2012 Trident Academy of Technology 21
22. Assignment Continued..
Populate the loan table with the following data
loan_number branch_name amount
L-11 Round Hill 900
L-14 Downtown 1500
L-15 Perryridge 1500
L-16 Perryridge 1300
L-17 Downtown 1000
L-23 Redwood 2000
L-93 Mianus 500
Copyright@2012 Trident Academy of Technology 22
23. Assignment Continued...
Populate the borrower realtion the following data
Customer_name loan_number
Adams L-16
Curry L-93
Hayes L-15
Jackson L-14
Jones L-17
Smith L-11
Smith L-23
Williams L-17
Copyright@2012 Trident Academy of Technology 23
24. Assignment Continued...
Populate account relation with the following data
account_number branch_name balance
A-101 Downtown 500
A-215 Mianus 700
A-102 Perryridge 400
A-305 Round Hill 350
A-201 Brighton 900
A-222 Redwood 700
A-217 Brighton 750
Copyright@2012 Trident Academy of Technology 24
25. Assignment Continued...
Populate the depositor relation with the following
data
Customer_name account_number
Hayes A-102
Johnson A-101
Johnson A-201
Jones A-217
Lindsay A-222
Smith A-215
Turner A-305
Copyright@2012 Trident Academy of Technology 25
26. Create One more table
Create a student table with the following data
Regdno Student_name Branch
1001 Surya CSE
1002 Binaya ETC
1003 Arup CSE
Add the CGPA Column, to the student table (the
type must be a floating point type)
Drop CGPA column
Modify the existing type of regdno.
Rename student to student_trident
Now delete all the data present in the student_trident
table.
Drop the table
Copyright@2012 Trident Academy of Technology 26