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

Post on 04-Jan-2016

213 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

Transcript

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

Tables of simple database of online-shop.

Database Application Development - Lecture 2

Description

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

Database Application Development - Lecture 2

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

• 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

• 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

• 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

Database Application Development - Lecture 2

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

• 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

Database Application Development - Lecture 2

Example of View

• 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

• 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

• Example of index

Database Application Development - Lecture 2

File

Geek

Un-indexed table

Indexed table

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

• 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

• 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

• 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

• 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

• 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

• 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

• 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

• 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

Database Application Development - Lecture 2

Float, Int

Some useful data type of Microsoft SQL Server

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

Chapter 1

Database Application Development - Lecture 2

top related