COLLABORATE ppsx

34 147 0
COLLABORATE ppsx

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

3C.1 Relational Database Desi g n L L E E S S S S O O N N : : 3 3 C C C C O O L L L L A A B B O O R R A A T T E E Relational Database Desi g n 3C.2 3C.3 Relational Database Desi g n K K N N O O W W L L E E D D G G E E B B Y Y T T E E Collaborate Lesson 3C / Slide 1 of 22©NIIT Collaborate Knowledge Byte In this section, you will learn about the following: • CODD’s Twleve Rules • Indexes • Recovery from Deadlock • Database Recovery In this section, you will learn about the following: CODD’s Twelve Rules Indexes Recovery from Deadlock Database Recovery Relational Database Desi g n 3C.4 CODD’s Twelve Rules Collaborate Lesson 3C / Slide 2 of 22©NIIT Collaborate Codd’s Twelve Rules • Dr. E.F. Codd presented twelve rules that a database must obey if it is to be considered truly relational. • These rules come out of Codd’s theoretical work on the relational model. • The rules stem from a single foundation rule-the zero rule: • For a system to qualify as a RELATIONAL, DATABASE, MANAGEMENT system, it must use its RELATIONAL facilities to MANAGE the DATABASE. • The twelve rules are as follows: • The information rule: This rule simply requires all information to be represented as data values in the rows and columns of tables. This is the basis of the relational model. • The guaranteed access rule: Every data value in a relational database should be logically accessible by specifying a combination of the table name, the primary key value, and the column name. 3C.5 Relational Database Desi g n Collaborate Lesson 3C / Slide 3 of 22©NIIT Collaborate Codd’s Twelve Rules (Contd ) • Systematic treatment of NULL values: The DBMS must support NULL values to represent missing or inapplicable information. They must be distinct from zero to spaces. The NULL values must be independent of data type. • Active online catalog based on the relational model: The system catalog tables hold the description of the database structure.These tables are created, owned, and maintained by the DBMS. They can be accessed by users in the same manner as the ordinary tables, depending on the user’s privileges. System tables are read-only. • The comprehensive data sublanguage rule: This rule states that the system must support at least all the following functions: • Data definition • View definition • Data manipulation operations • Security and integrity constraints • Transaction management operations Relational Database Desi g n 3C.6 Collaborate Lesson 3C / Slide 4 of 22©NIIT Collaborate Codd’s Twelve Rules (Contd ) • The view updating rule: All views that are theoretically updatable must be updatable by the system. • High level insert, update, and delete: This rule states that rows should be treated as sets in insert, delete, and update operations. It stresses on the set-oriented nature of the database. • Application programs must remain unimpaired when any changes are made in storage representation or access methods. • Logical data independence: Changes should not affect the user’s ability to work with the data. • Integrity independence: Integrity constraints must be storable in the system catalog. • Distribution independence: Database must allow manipulation of distributed data located on other computer systems. • Nonsubversion rule: The nonsubversion rule states that different levels of the language cannot subvert or bypass the integrity rules and constraints. Dr. E.F. Codd presented twelve rules that a database must obey if it is to be considered truly relational. These rules come out of Codd’s theoretical work on the relational model. No currently available RDBMS fully satisfies all twelve of Codd’s rules. The rules stem from a single foundation rule- the zero rule: For a system to qualify as a RELATIONAL, DATABASE, MANAGEMENT system, it must use its RELATIONAL facilities to MANAGE the DATABASE. The twelve rules are as follows: 1. The information rule: This rule simply requires all information to be represented as data values in the rows and columns of tables. This is the basis of the relational model. 2. The guaranteed access rule: Every data value in a relational database should be logically accessible by specifying a combination of the table name, the primary key value, and the column name. 3. Systematic treatment of NULL values: The DBMS must support NULL values to represent missing or inapplicable information. They must be distinct from zero to spaces. The NULL values must be independent of data type i.e NULL values for all types of data are the same. 3C.7 Relational Database Desi g n 4. Active online catalog based on the relational model: In an earlier session, we mentioned system tables or system catalog. The system catalog is a collection of tables that the DBMS maintains for its own use. These tables hold the description of the structure of the database. These tables are created, owned, and maintained by the DBMS. They can be accessed by users in the same manner as the ordinary tables, depending on the user’s privileges. System tables are read-only. 5. The comprehensive data sublanguage rule: This rule states that the system must support at least all the following functions: a. Data definition b. View definition c. Data manipulation operations d. Security and integrity constraints e. Transaction management operations 6. The view updating rule: All views that are theoretically updatable must be updatable by the system. 7. High level insert, update, and delete: This rule states that rows should be treated as sets in insert, delete, and update operations. It stresses on the set- oriented nature of the database. Just as the SELECT operation can deal with a set of rows, the other operations that modify the database should also deal with sets, and not only with single rows. This rule prevents DBMSs that support a row-at-a-time modification of the database. Therefore, the DBMS must allow multiple rows to be updated. 8. Physical data independence: Application programs must remain unimpaired when any changes are made in storage representation or access methods. 9. Logical data independence: Changes should not affect the user’s ability to work with the data. 10. Integrity independence: Integrity constraints must be storable in the system catalog. The concept of data integrity requires no further explanation. 11. Distribution independence: Database must allow manipulation of distributed data located on other computer systems. 12. Nonsubversion rule: The nonsubversion rule states that different levels of the language cannot subvert or bypass the integrity rules and constraints. For example, assume there is an application program that takes care of the integrity of data in a database. Another user can write another program, say in C language, which can bypass the integrity constraints imposed by the application program. Such an integrity violation is unacceptable in an RDBMS. Therefore, integrity constraints should be specified at the DBMS level, and not through application programs only. The DBMS must ensure that no other level can bypass the constraints specified to maintain the integrity of the database. Relational Database Desi g n 3C.8 Indexes Collaborate Lesson 3C / Slide 5 of 22©NIIT Collaborate Indexes • For direct access to records, you can design additional structures that can be linked with files. One such structure is an index. • An index for a file is like a catalog in a library. • The CREATE INDEX statement is used to create an index. • The DROP INDEX statement is used to remove an index. • The descriptions of indexes are stored in the system database. • When a table is dropped, all indexes created on that table are also dropped. A database query may reference only a portion of the records in a file. For example, the query “Find all customers located at Boston” references only a small portion of the file that stores customer records. If the system has to check this condition for each record, the efficiency of the system will be less. Therefore, there needs to be a method to access the required records directly. For direct access to records, you can design additional structures that can be linked with files. One such structure is an index. An index for a file is like a catalog in a library. There are two types of indexes: Primary: A primary index contains pointers that point directly to the file. Secondary: A secondary index contains pointers that do not point directly to the file. Instead, each pointer points to a bucket, which, in turn, contains pointers to the actual file. Secondary indexes improve the performance of queries that use keys other than the primary key. However, they have a disadvantage. They complicate the process of making any changes in the database. 3C.9 Relational Database Desi g n Like base tables, indexes are also created and dropped using SQL DDL statements. In a relational system, the user does not decide whether to use an existing index or not. This decision is taken by the query processor. The SQL statement for creating an index on the customer table is: CREATE INDEX x ON customer (cust-no) ASC The above statement creates an index named x, based on the ascending value of column cust-no. To define a descending index, you can specify DESC instead of ASC. You can also specify the UNIQUE option with the CREATE INDEX statement. For example, CREATE UNIQUE INDEX x ON customer (cust-no) ASC By specifying the UNIQUE option, you can ensure that no two records in the base table can take on the same value for the indexed column or column combination. This is a good way of ensuring non-duplicate rows in a table. If an existing table already violates the uniqueness constraint, an attempt to create a unique index will fail. The statement to drop an index is simply: DROP INDEX x The descriptions of indexes are also stored in the system database. When an index is dropped, its description is removed from the system catalog. When a table is dropped, all indexes created on that table are also dropped. Relational Database Desi g n 3C.10 Recovery from Deadlock Collaborate Lesson 3C / Slide 6 of 22©NIIT Collaborate Recovery from Deadlock • When a deadlock occurs, one or more transactions are rolled back to break the deadlock. • While performing the roll back operation, the following issues need to be addressed: • Selection of a victim - In the situation of a deadlock, you first need to determine the transaction (or transactions) that should be rolled back to break the deadlock. • Rollback - After determining the transaction to be rolled back, you need to determine how far the transaction is to be rolled back. • Starvation - To avoid starvation, you need to ensure that a transaction is picked as a victim for only a fixed number of times. Once it is determined that a deadlock exists, the system needs to recover from the deadlock. For this, one or more transactions are rolled back to break the deadlock. While performing the roll back operation, the following issues need to be addressed:  Selection of a victim: In the situation of a deadlock, you first need to determine the transaction (or transactions) that should be rolled back to break the deadlock. Such a transaction is called the victim transaction. The transaction that will lead to minimum loss, in terms of cost, should be chosen for rollback. The following factors determine the cost of a rollback: x How much execution has the transaction completed and for how much more time the transaction will execute to complete its task? x How many data items were used by the transaction? x How many more data items does the transaction need to complete? x How many transactions will be included in the rollback? Rollback: After determing the transaction to be rolled back, you need to determine how far the transaction is to be rolled back. The easiest answer to this problem is to do a total rollback, which means that the transaction will be aborted and restarted. [...]... Restricted access Collaborate Relational Database Design Lesson 3C / Slide 18 of 22 Collaborate Challenge (Contd ) 7 ©NIIT The table Item has the following columns: Item Code (primary key) Item Name Size Rate City State whether the following view is updatable Also, give the reason for your answer CREATE VIEW p (item name, size) AS SELECT item name, size FROM item WHERE rate > 150 Collaborate Relational... of 22 3C.26 Collaborate Challenge (Contd ) 8 9 ©NIIT 3C.27 Which of the following SQL statements are used to establish a security scheme for a database? 1 GRANT 2 CREATE 3 REVOKE 4 DROP State whether true or false: The entity integrity constraint states that the database must not contain any unmatched foreign key values Collaborate Relational Database Design Lesson 3C / Slide 20 of 22 Collaborate Challenge... Deadlocks Collaborate Best Practices Preventing Deadlocks • Each transaction should lock all its data items before it starts execution In addition, either all data items should be locked in one step or none of them is locked • Introduce a partial ordering of data items and enforce that a transaction can lock a data item only in the specified order • Use pre-emption and transaction rollbacks ©NIIT Collaborate. .. deadlock is broken As a worst case, sometimes, you might need to check for deadlock occurrence every time an allocation request cannot be granted immediately ©NIIT 3C.17 Collaborate Lesson 3C / Slide 12 of 22 Relational Database Design Collaborate FAQs (Contd ) Q Is there any method to test whether a subquery returns any rows as result? Ans: SQL provides the EXISTS clause to test whether a subquery returns... definition 3 Joined C It includes all columns but only some rows of the source table 4 Row-column subset D It includes all rows but only some columns of the source table Collaborate Relational Database Design Lesson 3C / Slide 14 of 22 Collaborate Challenge (Contd ) 2 ©NIIT Consider the following steps: 1 Transaction A retrieves record R at time T 2 Transaction B retrieves the same record at time T+1... (based on values seen at T) 4 Transaction B updates the same record at time T+3 (based on values seen at time T+1) What is the result of the above sequence of steps? Collaborate Relational Database Design Lesson 3C / Slide 15 of 22 3C.22 Collaborate Challenge (Contd ) 3 What is the problem with the following SQL statement? CREATE TABLE product (product-no CHAR(5), product-type CHAR(14), price DECIMAL... 2 The NOT NULL clause is not specified with the attribute a-no 3 The attribute names should not be in parentheses 4 The table name should be in parentheses ©NIIT 3C.23 Collaborate Lesson 3C / Slide 16 of 22 Relational Database Design Collaborate Challenge (Contd ) 4 ©NIIT Consider the following situation: A student has come to a university for registration Students in this university have to register... in American history 2 Found seat available 3 Student was granted admission 4 Checked for availability of seat for the course in Sociology 5 Found no seats available Collaborate Relational Database Design Lesson 3C / Slide 17 of 22 3C.24 Collaborate Challenge (Contd ) 6 Refused student admission to this course and offered registration to a course in Psychology 7 Registered student for both the courses... System errors • Logical errors • Hardware failures A transaction needs to be in one of the following two states to maintain data integrity: • Aborted state • Committed state Collaborate Lesson 3C / Slide 7 of 22 Relational Database Design Collaborate Database Recovery (Contd ) • • ©NIIT Database recovery involves the transaction log that stores a history of all the changes made to the database and the status... restore the database to the previous consistent state 3C.13 Relational Database Design FROM THE EXPERT’S DESK Collaborate From the Expert’s Desk • ©NIIT This section will introduce the following: • Best practices for preventing deadlocks • Tip on database recovery • FAQs on deadlocks and SQL statements Collaborate Lesson 3C / Slide 9 of 22 In this section, you will learn about best practices for preventing . Relational Database Desi g n K K N N O O W W L L E E D D G G E E B B Y Y T T E E Collaborate Lesson 3C / Slide 1 of 22©NIIT Collaborate Knowledge Byte In this section, you will learn about the following:. Database Recovery Relational Database Desi g n 3C.4 CODD’s Twelve Rules Collaborate Lesson 3C / Slide 2 of 22©NIIT Collaborate Codd’s Twelve Rules • Dr. E.F. Codd presented twelve rules that. primary key value, and the column name. 3C.5 Relational Database Desi g n Collaborate Lesson 3C / Slide 3 of 22©NIIT Collaborate Codd’s Twelve Rules (Contd ) • Systematic treatment of NULL values:

Ngày đăng: 01/08/2014, 09:21

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan