Chapter Four Objectives

advertisement
Chapter Four
Objectives
Introduction to SQL
 Introduction to iSQL*PLUS
 Types of SQL statements
 Concepts of DDL & DML
 Data Manipulation Language (DML)

SQL









Structured Query Language
Developed by IBM
Used in most Commercial DBMS
Statements are not case sensitive.
Statements can be on one or more lines.
Reserved words cannot be abbreviated or split over
lines.
Terminated with a semi colon.
Statements are entered at SQL prompt. The
subsequent lines are numbered (SQL buffer)
Only one statement can be current at any time in the
buffer.
2
Types of SQL Statements


Data Definition Language (DDL)
Data Manipulation Language (DML)
3

Example:
Student
(Name, ID, GPA, Major, B_Date)
Course
(C_Num, Dept, Title, Cr)
Student_Course
(ID, C_Num, Dept, Grade)
Faculty
(ID, Name, Dept, Salary, Area)
Faculty_Course
(ID, C_Num, Dept, Semester)
Department
(Name, Num_Faculty)
(Rank, Low_salary, High_salary)
Faculty_Status
4
Data Definition Language
Name:
User Identifiers:
1-30 characters
Start with an alphabet
Followed by alphabet, digit, _
Unique
Not reserved
Not case sensitive
5
Data Types
Oracle Data Types:




CHAR(size)
VARCHAR2(max_size)
NUMBER(n,d)
DATE
6
Data Types:
1-Character:
CHAR(Size)
VARCHAR2(MaxSize)
‘4321’
‘19 Main St. Frostburg’
‘*’
‘Student’’s ID’
7
Data Types:
2-Number:
NUMBER
NUMBER(T,D)
1,234,567.89
1,234,567.89
1,234,567.89
1,234,567.89
1,234,567.89
NUMBER
1,234,567.89
NUMBER(9) 1,234,567
NUMBER(9,1) 1,234,567.8
NUMBER(7,-2) 1,234,500
NUMBER(6)
??
8
Data Types:

3-Date:
DATE
MyBirthdate = ‘11-JAN-37’

Default time

Use TO_DATE()
00:00:00 A.M.
9
Display a Structure of a Table:
DESCRIBE
Student;
Name
Null?
Type
---------------------------------------------------------NAME
VARCHAR2(80)
ID
NUMBER(9)
GPA
NUMBER(3,2)
B_Date
Major
DATE
CHAR(4)
10
iSQL*PLUS

iSQL*Plus consists of the following
three layers:
1-Client layer (Web browser)
2-Middle layer (Oracle HTTP Server
and iSQL*Plus Server)
3-Database layer (Oracle database
and Oracle Net)
11
iSQL*PLUS
Interface Configuration


History Size: Set the number of scripts
displayed in the script history.
Input Area Size: Set the size of the
script input area.
-Width
-Height
12
iSQL*PLUS
Interface Configuration

Output Location: Set where script
output is displayed.
-Below Input Area
-Save to HTML File

Set whether output is displayed on a
single page, or over multiple pages.
-Single page
-Multiple pages

Number of rows on each page
13
iSQL*PLUS
Interface Configuration

Show Line Numbers
-On
-Off

Indent Attribute or Column Names
-On
-Off

Whether commands in scripts are displayed in output
as the script is executed.
-On
-Off
14
Changing the name of a table:
RENAME student TO GradStudent;
15
Download