PHYSICAL DATABASE DESIGN pps

46 179 1
PHYSICAL DATABASE DESIGN pps

Đ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

3A.1 Relational Database Desi g n L L E E S S S S O O N N : : 3 3 A A P P H H Y Y S S I I C C A A L L D D A A T T A A B B A A S S E E D D E E S S I I G G N N O O b b j j e e c c t t i i v v e e s s In this lesson, you will learn to:  Identify the following kinds of relations: x Base tables x Query results x Views  Create tables  Alter tables  Remove tables  Query tables and work on them  Define views  Perform DML operations on views  Identify the different types of views  Identify data integrity constraints 3A.2 Relational Database Desi g n Physical Database Design Lesson 9 / Slide 1 of 13©NIIT Physical Database Design Objectives In this section, you will learn to: • Identify the following kinds of relations: • Base tables • Query results • Views • Create tables • Alter tables • Remove tables • Query tables and work on them • Define views • Perform DML operations on views • Identify the different types of views • Identify data integrity constraints I I N N S S T T R R U U C C T T O O R R N N O O T T E E S S Lesson Overview The lesson covers the different kinds of relations. It also explains how to create, alter, remove, and query tables. In addition, the lesson explains the different types of views, the various DML operations that can be performed on them, and data integrity constraints. 3A.3 Relational Database Desi g n Physical Database Design©NIIT Physical Database Design Pre-assessment Questions 1. Functional dependencies represent _______ relationships. 2. What is the term used for the intentional introduction of redundancy in a table in order to improve performance? 3. Each value of an attribute A in relation R is associated with precisely one value of attribute B. What is this called? 4. A table is said to be in the _____ when each cell of the table contains precisely one value. 5. In a relation, every determinant is a candidate key. This relation is in which normal form? Lesson 9 / Slide 2 of 13 3A.4 Relational Database Desi g n Physical Database Design©NIIT Physical Database Design Solutions Ans1. Many-to-one Ans2. Denormalization Ans3. Functional dependency Ans4. First normal form Ans5. Boyce-Codd normal form Lesson 9 / Slide 3 of 13 3A.5 Relational Database Desi g n L L A A N N G G U U A A G G E E S S U U P P P P O O R R T T F F O O R R T T H H E E R R E E L L A A T T I I O O N N A A L L M M O O D D E E L L Physical Database Design Lesson 9 / Slide 4 of 13©NIIT Physical Database Design Language Support for the Relational Model • Most relational database systems support a query language named Structured Query Language (SQL). • SQL is a combination of three subordinate languages: • Data Definition Language (DDL) • Data Manipulation Language (DML) • Data Control Language (DCL) • The three important types of relations are: • Base tables • Query results • Views Most relational database systems support a query language named Structured Query Language (SQL). Like any other query language, SQL is a combination of three subordinate languages:  Data Definition Language (DDL) Data Manipulation Language (DML) Data Control Language (DCL) DDL statements include operators for creation and deletion of tables and indexes. DML statements are used to enter data into the tables created by using DDL statements. DML statements are also used to update and delete data and perform complex queries on the tables. DCL statements are used to control users’ access to the tables. 3A.6 Relational Database Desi g n Kinds of Relations A relational system can have different kinds of relations. However, the three important types of relations are: Base tables Query results Views Base Tables Physical Database Design Lesson 9 / Slide 5 of 13©NIIT Physical Database Design Base Tables • A base table is a named table that physically exists in a database. • The SQL statement to create a table is CREATE TABLE. • You can alter an existing table by using the ALTER TABLE statement. • You can remove a table by using the DROP TABLE statement. A base table is a named table that physically exists in a database. You can physically create a table after you have mapped the entity-relationship diagram to corresponding tables and normalized the tables. DDL statements are used to create tables. 3A.7 Relational Database Desi g n Creating Tables The SQL statement to create a table is CREATE TABLE. For example, the following statement creates the customer table: CREATE TABLE customer (cust-no CHAR(5) NOT NULL, name CHAR(15), phone-number CHAR(7), city CHAR(15), PRIMARY KEY (cust-no)) The CREATE TABLE statement is followed by the table name, which is customer in this example. Note that everything after the table name is enclosed in parentheses. The information in parentheses includes the column names or attributes of the customer table. The attributes in this example are cust-no, name, phone-number, and city. CHAR signifies that the column cust-no will contain character type of data. The size of the column is specified in parentheses after the name of the data type. The primary key is also defined in the above statement by using the PRIMARY KEY clause. The clause here signifies that the attribute cust-no is the primary key. The primary key should not contain any null values. Therefore, the NOT NULL clause has been specified with the attribute cust-no. The NOT NULL clause can be used to define any attribute as not null irrespective of whether the attribute is a primary key. For example, if you do not want any null values in the name column, the CREATE TABLE statement can be modified as: CREATE TABLE customer (cust-no CHAR(5) NOT NULL, name CHAR(15) NOT NULL, phone-number CHAR(7), city CHAR(15), PRIMARY KEY (cust-no)) Now, you will look at creating a table whose attribute refers to another table. For example, the SQL statement to create the sale table is: CREATE TABLE sale (cust-no CHAR(5), prod-no CHAR(5), qty DECIMAL(8,2), PRIMARY KEY (cust-no, prod-no), FOREIGN KEY (cust-no) REFERENCES customer, FOREIGN KEY (prod-no) REFERENCES product) If the primary key is made up of more than one attributes, then the attributes are named after the PRIMARY KEY clause and are separated by a comma. In the above example, the primary key is made up of two attributes, cust-no and prod-no. The FOREIGN KEY clause is followed by the name of the attribute. The REFERENCES clause is followed by the name of the table that the attribute references. 3A.8 Relational Database Desi g n Altering Tables You can alter an existing table by using the ALTER TABLE statement. For example, the SQL statement to include a column address in the customer table is: ALTER TABLE customer ADD address CHAR(20) The above statement adds a fifth column address in the customer table and assigns null to all values in the column. You cannot specify the NOT NULL clause with the ALTER TABLE statement. Removing Tables You can remove a table by using the DROP TABLE statement. For example, the SQL statement to remove the customer table is: DROP TABLE customer When a table is created, the description of the table is stored in the system catalog. The system catalog stores the names of tables, their attributes, and the data types of the attributes. The system catalog also stores other details like the users of the tables. Therefore, when you issue the DROP TABLE statement, the description of the specified table is removed from the system catalog. 3A.9 Relational Database Desi g n Query Results Physical Database Design Lesson 9 / Slide 6 of 13©NIIT Physical Database Design Query Results • The results of queries made on a table are also tables. • DML statements in SQL are used to query tables and work on them. • SELECT is the most powerful DML statement of SQL. All relational operations can be performed by using the SELECT statement. • You can remove the duplicate rows in queries by using the DISTINCT clause. • SQL can impose an order on the result of a query through the ORDER BY clause. • A query in which data is retrieved from more than one table is called a join query. • There are two types of joins, equi-join and self join. • The aggregate functions in SQL are COUNT, SUM, AVG, MAX, and MIN. 3A.10 Relational Database Desi g n Physical Database Design Lesson 9 / Slide 7 of 13©NIIT Physical Database Design Query Results (Contd ) • SQL provides a clause IS NULL (or IS NOT NULL) for finding a null value. • A query within a query is called a subquery. • The UNION operator of relational algebra is represented by the UNION clause in SQL. • You can enter data in a table by using the INSERT statement. • SQL provides the UPDATE statement for updating data. • SQL provides the DELETE statement to delete a row. The results of queries made on a table are also tables. For example, a query to list the names of all the customers in the customer table will result in the following table: NAME Tim Mary Johnson Ray Smith Query Result You will now learn about the four DML statements in SQL that are used to query tables and work on them. These statements are: SELECT, INSERT, UPDATE, and DELETE. [...]... Simplified structure Logical data independence Relational Database Design 3A.34 DATA INTEGRITY Physical Database Design Data Integrity • • • • ©NIIT Data integrity refers to the correctness and completeness of the data in a database Data integrity constraints restrict the data values that can be inserted into the database or updated in the database Some typical data integrity constraints are: • Required... Relational Database Design 3A.30 What are Views For? Physical Database Design What are Views For? • • ©NIIT Views are an important part of a relational DBMS because of the following reasons: • Valid information • Restricted access • Simplified access • Simplified structure • Logical data independence The disadvantages of using views are: • Views affect DBMS performance • A view may or may not be updatable Physical. .. delete the rows of all customers who are based in New York, the SQL statement is: DELETE FROM customer WHERE city = “New York” Relational Database Design 3A.20 Views Physical Database Design Views • • • • • ©NIIT A view is a named, derived, virtual table that does not exist physically The tables that are the source of the data visible through the view are referred to as source tables Views are defined by... definition Physical Database Design Lesson 9 / Slide 9 of 13 The different types of views are: Column subset Row subset Row-column subset Grouped Joined Column Subset A column subset view includes all rows but only some columns of the source table For example, the following CREATE VIEW statement creates a column subset view CREATE VIEW aa (emp-code, department) AS SELECT emp-code, dept Relational Database Design. .. definition of the view stored in the database The DBMS then translates the user’s request into an equivalent request against the source tables of the view In this way, the DBMS maintains the illusion of the view Views can be theoretically updatable or non-updatable Physical Database Design Lesson 9 / Slide 8 of 13 A view is a named, derived, virtual table that does not exist physically This is unlike a base... used because some views may be updatable on paper but they may not be updatable by the system in question Most RDBMS products do not support updation of views 3A.27 Relational Database Design Types of Views Physical Database Design Types of Views • ©NIIT The different types of views are: • Column subset: A column subset view includes all rows but only some columns of the source table • Row subset:... integrity: The database must not contain any unmatched foreign key values • Business rules: Many data integrity issues in the real world are concerned with the rules and procedures of an organization A trigger is an action that takes place when an event occurs Physical Database Design Lesson 9 / Slide 11 of 13 Data integrity refers to the correctness and completeness of the data in a database When the... the students understand the DDL statements used to manage tables: 1 What will be the statement to add a column, designation, to a table, employee? 2 What will be the statement to delete a table named product? Solutions: 1 ALTER TABLE employee ADD designation CHAR(20) Relational Database Design 3A.24 2 DROP TABLE product You can give the following additional information while explaining the SELECT statement:... may or may not be updatable Physical Database Design Lesson 9 / Slide 10 of 13 Views are an important part of a relational DBMS because of the following reasons: Valid information: Views enable different users see a database from different perspectives Only the part that is relevant to the users is visible to them Restricted access: Views restrict access to the database Different users are allowed... consistency and correctness of the data, an RDBMS imposes some data integrity constraints Data integrity constraints restrict the data values that can be 3A.35 Relational Database Design inserted into the database or updated in the database Some typical data integrity constraints are: Required data Validity checking Entity integrity Referential integrity Business rules Integrity constraints are effectively . Views Base Tables Physical Database Design Lesson 9 / Slide 5 of 13©NIIT Physical Database Design Base Tables • A base table is a named table that physically exists in a database. • The SQL. performed on them, and data integrity constraints. 3A.3 Relational Database Desi g n Physical Database Design NIIT Physical Database Design Pre-assessment Questions 1. Functional dependencies represent. in which normal form? Lesson 9 / Slide 2 of 13 3A.4 Relational Database Desi g n Physical Database Design NIIT Physical Database Design Solutions Ans1. Many-to-one Ans2. Denormalization Ans3.

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