Download Lecture1

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
ISO6 Relational
Databases
Simon Booth
Email [email protected]
Room Library S6
Tel: 7247
Course Aims
Develop a basic proficiency in
 A relational database environment
 The SQL database language –
Oracle SQL*Plus
 A forms-based 4GL programming
tool – Access 97
 Database design and Management
2
PF Lecture 1
Lectures and
Workshops

Lectures (A1)


Monday 10-11
Workshop (2A19)

Monday 14-16
3
PF Lecture 1
Applications and Books




SQL Plus Oracle 3.3/8.0
Oracle 8 database
Access 97
Database Design and Management by
Nick Dowling (Letts) £10.99
4
PF Lecture 1
Proposed Course
Structure



First half – SQL Plus version 3.3/8.0
running against Oracle 8
Second half – Access 97
Lecture on Monday – practical issues on
the upcoming workshops
5
PF Lecture 1
Database Management
Systems (DBMS)
Definition
“ A set of programs that act as an
interface between application
programs and the data in the
database”
6
PF Lecture 1
A Simplified Database System Environment
users/programmers
Database
Application Programs/Queries
System
DBMS
Software
Software to process
Queries/Programs
Software to access
Stored Data
Stored Database
Definition
(Meta-Data)
PF Lecture 1
Stored
Database
7
5 primary functions of a DBMS





Define, create and organize a database (Data
Definition Language)
Input data
Process data (Data Manipulation Language)
Maintain Data integrity and security
Query database (Structured Query Language)
8
PF Lecture 1
Advantages of DBMS

Data independence




Access to data based on its
contents and its associations with
other data
Physical organization of data is
independent of program using it
Reduction in data redundancy
Accessing and processing data
more effective
users
users
users
users
PF Lecture 1
DATA
users
9
Disadvantages of DBMS



Cost is the primary disadvantage
Mainframe hardware expensive
Even expensive with PC based
databases
Licences
 Training
 Maintenance and Management

10
PF Lecture 1
Database Infrastructures
Hierarchical
 Network
 Relational

11
PF Lecture 1
Hierarchical
ROOT
Father
Son 1
Son 2
12
PF Lecture 1
Network
Owner
Member
13
PF Lecture 1
Relational Model
STUDENT Name
StudentNumber Year MajorSubject
Smith
17
1
COSC
Brown
8
2
COSC
COURSE
CourseName CourseNumber UnitsPassed Dept.
CompSci Intro
Data Models
Discrete Math
COSC1310
COSC3320
MATH2410
2
1
3
COSC
COSC
MATH
Databases
COSC3380
3
COSC
TUTORIALS TutorialID CourseNumber Semester Year Tutor
85
92
102
112
MATH2410
COSC1310
COSC3320
MATH2410
EXAM_RESULT
PF Lecture 1
Aut
Aut
Spring
Aut
95
95
96
95
Donnelly
Simler
Munro
Bell
StudentNumber TutorialID
17
112
17
119
8
85
8
92
8
102
Grade
B
C
A
A
B
14
Structured Query
Language (SQL)




Programming language (4GL)
Data definition and data
manipulation language
Used in all types of database
applications
Oracle and Access
15
PF Lecture 1
SQL (cont.)





Provided a degree of homogeneity
Industry standard
Databases conforming to the SQL
standard can also use applications
from other SQL databases
SQL standards approved by ANSI
Incorporating SQL technology
provides a strong selling point
16
PF Lecture 1
SQL Plus (Sequel Plus)

SQL*Plus is a program for working with an
ORACLE database
Create tables
 Store information in the tables
 Retrieve information in a form you choose,
performing calculations on it and combining it in
new ways
 Maintain the database

17
PF Lecture 1
Querying &
Manipulating
Databases
Using SQL*Plus
Accessing SQL*Plus 3.3
To access Oracle SQL*Plus you
must first log-on in the normal way.
In Windows NT go to START,
PROGRAMS, ORACLE, ORACLE
WinNT, SQL Plus 3.3.

19
PF Lecture 1
Accessing SQL

Enter your oracle
username and password.
You will also be asked for a
‘host string’ enter ora1a11
20
PF Lecture 1
Accessing SQL


Having entered these, you will
then see the SQL prompt from
Oracle:
SQL>
You are now ready to type
SQL commands
21
PF Lecture 1
Accessing SQL


SQL>SELECT job FROM emp
2
Note: Oracle itself is not casesensitive. I have used a mixture of
upper and lower case to indicate
SQL commands (uppercase) and
the components I select (lowercase)
22
PF Lecture 1
Accessing SQL


SQL>SELECT job FROM emp
2
Note: Oracle inserts the “2” to indicate
that we are on the second line. To
properly terminate the command, enter
;. Oracle will now process the
command.
23
PF Lecture 1
A table
Artist
Verve
Oasis
Title
Format
Urban Hymns CD
Be Here Now Cassette
Radiohead Bends

CD
The above is a table named called “music” with
three columns: Artist, Title and Format. There
are presently three rows.
24
PF Lecture 1
The Select command

To list the columns Artist
and Format from the table
music:
SQL> SELECT artist,
format FROM music;
25
PF Lecture 1
The WHERE clause


We can select based on rows that
meet a certain condition. For
instance, only CD’s:
SQL> SELECT * FROM music
2 WHERE format LIKE ‘CD’;
* means all columns
26
PF Lecture 1
The WHERE clause(2)


Another Example:
SQL> SELECT ename, deptno, sal
2 FROM emp
3 WHERE sal >= 1500;
Columns are listed in the order they
appear and can appear more than
once
27
PF Lecture 1
The ORDER BY clause

Oracle will list back the
information we ask in order it
appears in the table. If we
want it alphabetically or by
numerical order we must add
an ORDER BY and specify the
column(s) to order by.
28
PF Lecture 1
The ORDER BY
clause(2)

Example:
SQL> SELECT ename,
deptno, sal
2 FROM emp
3 ORDER BY sal DESC;
29
PF Lecture 1
SQL

Group Functions
These functions (AVG, MAX, MIN, etc) can
act on entire tables or subsets of the table
SELECT AVG(sal) FROM emp;
SELECT MAX(sal) FROM emp
WHERE job = ‘MANAGER’;
SELECT COUNT(*) FROM emp
WHERE deptno = 20;
30
PF Lecture 1
GROUP BY

Group functions can also be used
with the GROUP BY clause, which
splits the table into specified groups,
returning one row for each group
SELECT AVG(sal), deptno FROM
emp
GROUP BY deptno;
31
PF Lecture 1
Clauses

Clauses can be combined:
SQL> SELECT ename,
deptno, sal
2 FROM emp
3 WHERE sal > 1500
4 ORDER BY sal DESC;
32
PF Lecture 1
Second example

Rows maybe selected by
WHERE
SELECT AVG(sal), deptno
FROM emp
WHERE job != ‘MANAGER’
GROUP BY deptno;
33
PF Lecture 1
Update

The SQL command update is
used to modify all or some
rows in the table:
UPDATE table
SET column = expr [, column =
expr]
[WHERE condition];
34
PF Lecture 1
Update

Example: correct name for
employee 7369
UPDATE emp
SET ename = ‘jones’
WHERE empno = 7369;
35
PF Lecture 1
Delete

The SQL command delete is
used to remove all or some
rows in the table:
DELETE FROM table
[WHERE condition];
36
PF Lecture 1
Delete

Example: remove employee
7369
DELETE FROM emp
WHERE empno = 7369;
37
PF Lecture 1
Copying Tables

We can copy tables existing tables:
CREATE TABLE stolen_table AS
SELECT * FROM another_table;
38
PF Lecture 1
Creating Tables(2)

If we only want specific columns, we
name them in the select;
If we only want specific rows, we use a
WHERE clause:
CREATE TABLE stolen_table AS
SELECT video_no, title FROM video
WHERE title = ‘T%’;
39
PF Lecture 1
Populating Tables


To place data in a table we use the INSERT
command:
INSERT INTO table [(column-name, …)]
VALUES (value, … );
Which adds one row to the table. To add
more, we have more INSERT commands
40
PF Lecture 1
Populating Tables

Examples:
INSERT INTO dept (deptno, dname)
VALUES (50, ‘Marketing’);
INSERT INTO dept
VALUES (50, ‘Marketing’, ‘Stirling’);
41
PF Lecture 1
Summary of SQL
commands

SQL
 SELECT
 UPDATE
 DELETE
 CREATE
AS
 INSERT
42
PF Lecture 1