Top Banner
Er. Nawaraj Bhandari Topic 11 Implementation
28

Implementation

Aug 19, 2015

Download

Education

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Implementation

Er. Nawaraj Bhandari

Topic 11Implementation

Page 2: Implementation

Aspects of Implementation

Creating...

Tables Domains Indexes Views

Page 3: Implementation

Create Table

The various ‘create table’ statements will be run as part of a script.

Any domains referred to, if they are created as separate objects in the database, will need to be created first.

Page 4: Implementation

Create Domain

Explicitly create a domain:

Create domain Allowable_Colours as Char Default ‘Red’ Check (Value in (‘Red’,’Blue’,’Green’));

Page 5: Implementation

Types of Constraints

Referential integrity Propagation constraints Domain constraints Table constraints

Plus... Constraint Violation

Page 6: Implementation

Referential Integrity Constraint

Create table workers(emp_no number(5) not null,first_name varchar(30),last_name varchar(30),job_title varchar(30),age number(3),dept_no number(5),primary key emp_no,foreign key (dept_no) references

Page 7: Implementation

Propagation Constraint

What happens if we delete a Boat from our Boat Hire database?

There are lots of Rental records that reference it. What happens to them?

Page 8: Implementation

Table with Propagation Constraint

Create Table Rental(BoatID number NOT NULL,CustomerID number NOT NULL,RentalStartDate date NOT NULL,RentalEndDate date NOT NULL,Primary Key (BoatID, CustomerID, RentalStartDate)Foreign Key (CustomerID) REFERENCES Customer(CustomerID),Foreign Key (BoatID) REFERENCES Boat (BoatID)On delete no actionOn update cascade);

Page 9: Implementation

Options for Propagation

No action Cascade Set Default Set Null

Page 10: Implementation

Domain Constraints

Boat Type could be enforced as...

a check constraint separate domain using Create Domain

statement as a foreign key to another table

Page 11: Implementation

Check Constraint

Create Table Boat

(BoatID number NOT NULL,

BoatName varchar (30) NOT NULL,

BoatType varchar (20),

Primary Key (BoatID)

Check (BoatType in ‘Yacht’,’Cruiser’,’Rower’));

Page 12: Implementation

As a Separate Domain

Create Domain BoatType As varchar(20) Default ‘Yacht’ Check (Value in (‘Yacht’,’Cruiser’,’Rower’)); The table’Boat’ will set the BoatType attribute as this domain

BoatType. Create Table Boat(BoatID number NOT NULL,BoatName varchar (30) NOT NULL,BoatTypeCode BoatType,Primary Key (BoatID));

Page 13: Implementation

As a Separate TableCreate Table BoatType(BoatTypeCode Varchar(3),BoatTypeDescription Varchar(20)Primary Key (BoatTypeCode));

With the corresponding Foreign Key in BoatCreate Table Boat(BoatID number NOT NULL,BoatName varchar (30) NOT NULL,BoatTypeCode varchar (3),Primary Key (BoatID)Foreign Key (BoatTypeCode) References BoatType;

Page 14: Implementation

Table ConstraintsCreate Table Rental(BoatID number NOT NULL,CustomerID number NOT NULL,RentalStartDate date NOT NULL,RentalEndDate date NOT NULLConstraint MaximumRentalsCheck(Not Exists(Select BoatIDFrom RentalsGroup By BoatIDHaving Count(*) >10)),Primary Key (BoatID, CustomerID, RentalStartDate)Foreign Key (CustomerID) REFERENCES Customer(CustomerID),Foreign Key (BoatID) REFERENCES Boat (BoatID)On delete no actionOn update cascade);

Page 15: Implementation

Inserting Data The basic SQL feature for inserting multiple rows:

INSERT INTO ''TABLE'' (''column-name'', [''column-name', ...])

VALUES (''1st row value a'',"1st row value b"),

(''2nd row value a', "2nd row value b"),

...

Example

Insert into boats (boatID, boatName)

Values (1,'Esmerelda'),

(2,'Missy'),

(3,'Lord George');

Page 16: Implementation

Data Loading Tools

Bulk insert in SQL server http://sqlserver2000.databases.aspfaq.com/how-do-i-

load-text-or-csv-file-data-into-sql-server.html Oracle SQL loader http://oreilly.com/catalog/orsqlloader/chapter/ch01.html My-SQL uses something called 'Bulk Insert' http://mysql.bigresource.com/Bulk-insert-from-text-

files-dDPRzHYo.html#2t6P0D5I

Page 17: Implementation

Server

Database

Network

Internet

Server

Applications

Other systems

http://192.168.2.223:5560/isqlplus

Page 18: Implementation

Oracle

For many years, Oracle was the largest market share AND largest by value.

It was challenged recently by MySQL.

Page 19: Implementation

Support for Languages

Java Programming – allowing sophisticated manipulation of data using the logic of a programming language

XML – allowing development of own tags so capable of transmitting data in almost any format

Page 20: Implementation

Support for...

Distributed database features Advanced security Data warehousing Internet ready features

Page 21: Implementation

Objects

Tables, indexes, views, domains... More complex objects with internal structure PL/SQL Stored functions Stored procedures Triggers

Page 22: Implementation

Oracle Architecture

Database

Database Instance

Logical and Physical structure

Page 23: Implementation

Logical Structure of Oracle

Tables spaces – logical storage units that contain the other objects, which have memory divided into blocks, extents, and segments.

Database schemas contain or own the objects like tables.

Definition of users

Page 24: Implementation

Physical Structure of Oracle DatafilesDatabase datafiles are physical files stored on disk. These files are used to store data on disk. Database datafiles are only written to by the DBWR processes

Redo logsLike a tape recorder that records every change in the Oracle database. As changes occur, they are regularly recorded in the online redo logs, just like you might record a movie on your VCR.

Control filesThe Control File of the database is a binary file that contains a great deal of database information. The control file contains the database name, data about the database log files. Oracle cannot function without valid control files.

Page 25: Implementation

Oracle Instance Contains all the processes and memory areas. A database instance is a set of memory structures that manage

database files The instance manages its associated data and serves the users of the

database. Also contains...

Page 26: Implementation

Oracle Instance

- System Global Area: When an instance is started, Oracle Database allocates a memory area called the SGA.

- Program Global Area: A PGA is a memory region that contains data and control information for a server process. It is no shared memory created by Oracle Database when a server process is started

- User Processes: User roles and user management

Page 27: Implementation

References Benyon-Davis, P. (2003). Database Systems, 3rd edition. Palgrave Macmillan. Chapter 12. Connolly, T. & Begg, C. (2004). Database Systems: A Practical Approach to Design,

Implementation, and Management, 4th Edition. Addison Wesley. Chapters 8 & 17.

Page 28: Implementation

ANY QUESTIONS?