Docsity

Database Systems: An Introduction to SQL - Prof. Mark Llewellyn, Study notes of Deductive Database Systems

Partial preview of the text

Download Database Systems: An Introduction to SQL - Prof. Mark Llewellyn and more Study notes Deductive Database Systems in PDF only on Docsity!

COP 4710: Database Systems (Chapter 5)

Page 1

Mark Llewellyn

COP 4710: Database Systems

Fall 2007

Chapter 5 – Introduction To SQL – Part 1

COP 4710: Database Systems

Fall 2007

Chapter 5 – Introduction To SQL – Part 1

School of Electrical Engineering and Computer Science

University of Central Florida

Instructor :

Dr. Mark [email protected] 236, 407-823-2790http://www.cs.ucf.edu/courses/cop4710/fall

COP 4710: Database Systems (Chapter 5)

Page 2

Mark Llewellyn

The Physical Design Stage of SDLC

Purpose –programming, testing,training, installation, documentingDeliverable – operational programs,documentation, training materials,program/data structures

Database activity –physical database design anddatabase implementation

Project Identification

and Selection

Project Initiation

and Planning

Analysis

Physical Design

Implementation

Maintenance

Logical Design

Implementation

Physical Design

COP 4710: Database Systems (Chapter 5)

Page 4

Mark Llewellyn

Benefits of a Standardized Relational

Language

• Reduced training costs• Productivity• Application portability• Application longevity• Reduced dependence on a single vendor• Cross-system communication

COP 4710: Database Systems (Chapter 5)

Page 5

Mark Llewellyn

The SQL Environment

Catalog

– A set of schemas that constitute the description of a database.

Schema

– The structure that contains descriptions of objects created by a

user (base tables, views, constraints).

Data Definition Language (DDL)

– Commands that define a database, including creating, altering,

and dropping tables and establishing constraints.

Data Manipulation Language (DML)

– Commands that maintain and query a database.

Data Control Language (DCL)

– Commands that control a database, including administering

privileges and committing data.

COP 4710: Database Systems (Chapter 5)

Page 7

Mark Llewellyn

Some SQL Data Types (from Oracle 9i)

String types

CHAR(n) – fixed-length character data, n characters longMaximum length = 2000 bytes

VARCHAR2(n) – variable length character data, maximum 4000bytes

LONG – variable-length character data, up to 4GB. Maximum 1per table

Numeric types

NUMBER(p,q) – general purpose numeric data type

INTEGER(p) – signed integer, p digits wide

FLOAT(p) – floating point in scientific notation with p binarydigits precision

Date/time type

DATE – fixed-length date/time in dd-mm-yy form

COP 4710: Database Systems (Chapter 5)

Page 8

Mark Llewellyn

DDL, DML, DCL, and the database development process

COP 4710: Database Systems (Chapter 5)

Page 10

Mark Llewellyn

Table Creation

General syntax for CREATE TABLE

Steps in table creation: 1.

Identify data types forattributes

Identify columns that canand cannot be null

Identify columns that mustbe unique (candidate keys)

Identify primary key-foreign key mates

Determine default values

Identify constraints oncolumns (domainspecifications)

Create the table andassociated indexes

COP 4710: Database Systems (Chapter 5)

Page 11

Mark Llewellyn

Examples of SQL database definition commands

COP 4710: Database Systems (Chapter 5)

Page 13

Mark Llewellyn

Non-null specification

Identifying primary key

Primary keyscan never haveNULL values

COP 4710: Database Systems (Chapter 5)

Page 14

Mark Llewellyn

Non-null specifications

Primary key

Some primary keys are composite –

composed of multiple attributes

COP 4710: Database Systems (Chapter 5)

Page 16

Mark Llewellyn

Primary key ofparent table

Identifying foreign keys and establishing relationships

Foreign key ofdependent table

COP 4710: Database Systems (Chapter 5)

Page 17

Mark Llewellyn

Data Integrity Controls

• Referential integrity – constraint that ensures

that foreign key values of a table must matchprimary key values of a related table in 1:Mrelationships.

• Restricting:

– Deletes of primary records.– Updates of primary records.– Inserts of dependent records.

COP 4710: Database Systems (Chapter 5)

Page 19

Mark Llewellyn

Changing and Removing Tables

• ALTER

TABLE

statement

allows

you

to

change column specifications:

– ALTER

TABLE

CUSTOMER_T

ADD

(TYPE

VARCHAR(2))

• DROP

TABLE

statement

allows

you

to

remove tables from your schema:

– DROP TABLE CUSTOMER_T

COP 4710: Database Systems (Chapter 5)

Page 20

Mark Llewellyn

Schema Definition

Control processing/storage efficiency:

– Choice of indexes– File organizations for base tables– File organizations for indexes– Data clustering– Statistics maintenance

Creating indexes

– Speed up random/sequential access to base table data– Example

• CREATE INDEX NAME_IDX ON

CUSTOMER_T(CUSTOMER_NAME)

• This makes an index for the CUSTOMER_NAME field of the

CUSTOMER_T table