Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "13.11.2015 DAT602 Database Application Development Lecture 2 Review of Relational Database."— Presentation transcript:

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

2 13.11.2015 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

3 13.11.2015 Tables of simple database of online-shop. Database Application Development - Lecture 2 UserInfo ID Name Password Item ID Name Price Description Transaction ID Date Buyer ItemID Amount

4 13.11.2015 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. Row Cells in the same row are members of a group of related items. Column Cells in the same column are members of a set of similar items. Key Each table defines a key made up of one or more columns that uniquely identify each row. Database Application Development - Lecture 2

5 13.11.2015 Database Application Development - Lecture 2 Source : Java Database Programming Bible. by John O'Donahue ISBN:0764549243

6 13.11.2015 Primary Keys Each 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

7 13.11.2015 Primary Keys In 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

8 13.11.2015 Foreign Keys A 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

9 13.11.2015 Database Application Development - Lecture 2 Source : Java Database Programming Bible. by John O'Donahue ISBN:0764549243

10 13.11.2015 View A 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

11 13.11.2015 Database Application Development - Lecture 2 Example of View

12 13.11.2015 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

13 13.11.2015 Index One 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

14 13.11.2015 Example of index Database Application Development - Lecture 2 Word (index) … Easy File Fish Game Geek Greece Machine … Word … Greece Machine Fish Easy Game File Geek … Un-indexed tableIndexed table

15 13.11.2015 What is transaction ? A transaction is a sequence of operations performed 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

16 13.11.2015 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

17 13.11.2015 Example of Transaction A 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

18 13.11.2015 Roll back Failure of any single step of transaction can cause cancellation of whole transaction. All involved data must be restored. Committed All steps of transaction must be completed to make transaction be committed. Database Application Development - Lecture 2

19 13.11.2015 Relationships Tables 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

20 13.11.2015 One-to-many Every 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_ID User_Name 1Amy 2Bob 3Chase 4Daisy User_IDFlight_NO 1CK912 2LH1908 2SA209 3JD109 3RG94 3TG234 3HG47 Table: User_Info Table: Flight_Info

21 13.11.2015 Many-to-many relationship Many-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

22 13.11.2015 Managing Database Users Give 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

23 13.11.2015 Different database systems have different data types. They share some common types. Some useful data type of Microsoft SQL Server float, money, datetime, Smalldatetime, varchar, char, bit, int, image Database Application Development - Lecture 2

24 13.11.2015 Database Application Development - Lecture 2 Type Float, Int moneyCan be negative SmalldatetimeFrom Jan 1, 1900 to Jun 6, 2079, 1 minute accuracy char Fixed-length non-Unicode character data with a maximum length of 8,000 characters varchar Variable-length non-Unicode data with a maximum of 8,000 characters. Text Variable-length non-Unicode data with a maximum length of 2,147,483,647 characters. image Variable-length binary data with a maximum length of 2,147,483,647 bytes bit0 or 1, true of false Some useful data type of Microsoft SQL Server

25 13.11.2015 Literature used “Java Database Programming Bible”, by John O'Donahue ISBN:0764549243 John Wiley & Sons © 2002 Chapter 1 Database Application Development - Lecture 2


Download ppt "13.11.2015 DAT602 Database Application Development Lecture 2 Review of Relational Database."

Similar presentations


Ads by Google