Top Banner
DAT602 Database Applic ation Development Lecture 2 Review of Relat ional Database
25

13.11.2015 DAT602 Database Application Development Lecture 2 Review of Relational Database.

Jan 04, 2016

Download

Documents

Malcolm Skinner
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: 13.11.2015 DAT602 Database Application Development Lecture 2 Review of Relational Database.

DAT602 Database Application Development

Lecture 2 Review of Relational Database

Page 2: 13.11.2015 DAT602 Database Application Development Lecture 2 Review of Relational Database.

What is relational database ?• A relational database is a database that

groups data using common attributes found in the data set.

• Relational databases use Table to organize all data. Database is consisted by tables.

Database Application Development - Lecture 2

Page 3: 13.11.2015 DAT602 Database Application Development Lecture 2 Review of Relational Database.

Tables of simple database of online-shop.

Database Application Development - Lecture 2

Description

Page 4: 13.11.2015 DAT602 Database Application Development Lecture 2 Review of Relational Database.

Some basic terms you should be familiar with• Table

All data in a relational database is explicitly represented at the logical level as values in tables.

• RowCells in the same row are members of a group of related items.

• ColumnCells in the same column are members of a set of similar items.

• KeyEach table defines a key made up of one or more columns that uniquely identify each row.

Database Application Development - Lecture 2

Page 5: 13.11.2015 DAT602 Database Application Development Lecture 2 Review of Relational Database.

Database Application Development - Lecture 2

Source : Java Database Programming Bible. by John O'Donahue ISBN:0764549243

Page 6: 13.11.2015 DAT602 Database Application Development Lecture 2 Review of Relational Database.

• Primary KeysEach table can have only one primary key, which can be any column or group of columns in the table having a unique value for each row.Primary keys can be simple or composite. A simple key is a key made up of one column, whereas a composite key is made up of two or more columns.

Database Application Development - Lecture 2

Page 7: 13.11.2015 DAT602 Database Application Development Lecture 2 Review of Relational Database.

• Primary KeysIn practice, the most common type of key is a column of unique integers specifically created for use as the primary key.For example: Customer ID, personal ID, etc.

NOTE:Normally, using integers is more efficient than string.Primary key can not be NULL.

Database Application Development - Lecture 2

Page 8: 13.11.2015 DAT602 Database Application Development Lecture 2 Review of Relational Database.

• Foreign KeysA foreign key is a column in a table used to reference a primary key in another table.

By using primary – foreign keys pair, developers can combine multiple tables together. See following example.

Database Application Development - Lecture 2

Page 9: 13.11.2015 DAT602 Database Application Development Lecture 2 Review of Relational Database.

Database Application Development - Lecture 2

Source : Java Database Programming Bible. by John O'Donahue ISBN:0764549243

Page 10: 13.11.2015 DAT602 Database Application Development Lecture 2 Review of Relational Database.

• ViewA view is a virtual table whose contents are defined by a query.Normally, a view does not exist as a stored set of data values in a database. The rows and columns of data come from tables referenced in the query defining the view and are produced dynamically when the view is referenced.

Database Application Development - Lecture 2

Page 11: 13.11.2015 DAT602 Database Application Development Lecture 2 Review of Relational Database.

Database Application Development - Lecture 2

Example of View

Page 12: 13.11.2015 DAT602 Database Application Development Lecture 2 Review of Relational Database.

• Why we need view ?A view acts as a filter on the underlying tables referenced in the view. The query that defines the view can be from one or more tables or from other views in the current or other databases.

Database Application Development - Lecture 2

Page 13: 13.11.2015 DAT602 Database Application Development Lecture 2 Review of Relational Database.

• IndexOne of purposes of creating index is accelerating retrieval speed.By applying index, query operation does not need to scan all records for getting matched result.Index sorts all records by specific rule.

Database Application Development - Lecture 2

Page 14: 13.11.2015 DAT602 Database Application Development Lecture 2 Review of Relational Database.

• Example of index

Database Application Development - Lecture 2

File

Geek

Un-indexed table

Indexed table

Page 15: 13.11.2015 DAT602 Database Application Development Lecture 2 Review of Relational Database.

What is transaction ?• A transaction is a sequence of operations perf

ormed as a single logical unit of work. A logical unit of work must exhibit four properties, called the atomicity, consistency, isolation, and durability (ACID) properties, to qualify as a transaction.

Database Application Development - Lecture 2

Page 16: 13.11.2015 DAT602 Database Application Development Lecture 2 Review of Relational Database.

• ACID- atomicity : either all of its data modifications are performed, or none of them is performed.- consistency : When completed, a transaction must leave all data in a consistent state- isolation : Modifications made by concurrent transactions must be isolated from the modifications made by any other concurrent transactions.- durability : After a transaction has completed, its effects are permanently in place in the system.

Database Application Development - Lecture 2

Page 17: 13.11.2015 DAT602 Database Application Development Lecture 2 Review of Relational Database.

• Example of TransactionA transaction is a group or sequence of commands, all of which must be executed in order and all of which must completed successfully.

Database Application Development - Lecture 2

Select items

Confirm select items

Pay online

Confirm

payment

Save deal

Page 18: 13.11.2015 DAT602 Database Application Development Lecture 2 Review of Relational Database.

• Roll backFailure of any single step of transaction can cause cancellation of whole transaction.All involved data must be restored.

• CommittedAll steps of transaction must be completed to make transaction be committed.

Database Application Development - Lecture 2

Page 19: 13.11.2015 DAT602 Database Application Development Lecture 2 Review of Relational Database.

• RelationshipsTables can be related in one of three ways:- One-to-one

every row in the first table has a corresponding row in the second table.

- One-to-many- Many-to-many

Database Application Development - Lecture 2

Page 20: 13.11.2015 DAT602 Database Application Development Lecture 2 Review of Relational Database.

• One-to-manyEvery row in the first table can have zero, one, or many corresponding rows in the second table. But for every row in the second table, there is exactly one row in the first table.

Database Application Development - Lecture 2

User_Name

Table: User_Info Table:

Flight_Info

Page 21: 13.11.2015 DAT602 Database Application Development Lecture 2 Review of Relational Database.

• Many-to-many relationshipMany-to-many relationships can't be directly modeled in a relational database. They must be broken into multiple one-to-many relationships.

Database Application Development - Lecture 2

Page 22: 13.11.2015 DAT602 Database Application Development Lecture 2 Review of Relational Database.

• Managing Database UsersGive different authorities to different kinds of users.Administrators have highest authority, such as create, delete tables.Generally, normal users have limited authority, they can alter data, but can’t delete or create tables.

Database Application Development - Lecture 2

Page 23: 13.11.2015 DAT602 Database Application Development Lecture 2 Review of Relational Database.

• Different database systems have different data types. They share some common types.

• Some useful data type of Microsoft SQL Serverfloat, money, datetime, Smalldatetime, varchar, char, bit, int, image

Database Application Development - Lecture 2

Page 24: 13.11.2015 DAT602 Database Application Development Lecture 2 Review of Relational Database.

Database Application Development - Lecture 2

Float, Int

Some useful data type of Microsoft SQL Server

Page 25: 13.11.2015 DAT602 Database Application Development Lecture 2 Review of Relational Database.

• Literature used“Java Database Programming Bible”,by John O'Donahue ISBN:0764549243John Wiley & Sons © 2002

Chapter 1

Database Application Development - Lecture 2