Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 11: Physical Database Design Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph S. Valacich, Jeffrey A. Hoffer.

Similar presentations


Presentation on theme: "Chapter 11: Physical Database Design Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph S. Valacich, Jeffrey A. Hoffer."— Presentation transcript:

1 Chapter 11: Physical Database Design Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph S. Valacich, Jeffrey A. Hoffer

2 Chapter Objectives Af ter studying this chapter you should be able to: – Understand the purpose of SQL – Design database fields. – Evaluate denormalization situations. – Design file organization structures. – Design object-relational features.

3

4 What Is Physical Database Design? The part of a database design that deals with data integrity, efficiency, referential integrity, data access and security for the access of data Processing speed, storage space, and data manipulation are key issues in physical database design

5 What Is SQL? Structured Query Language Often pronounced “sequel” The standard language for creating and using relational databases ANSI Standards –SQL-92 – most commonly available –SQL-99 – included object-relational features

6 Common SQL Commands CREATE TABLE – used to define table structures and link tables together SELECT – used to retrieve data using specified formats and selection criteria INSERT – used to add new rows to a table UPDATE – used to modify data in existing table rows DELETE – used to remove rows from tables

7 Example CREATE TABLE Statement Create Table DEPT ( deptno number(2) not null, deptnamevarchar2(14), locationvarchar2(13), constraint DEPT_PK primary key (deptno) ) Here, a table called DEPT is created, with a numeric primary key (deptno) and two text fields (deptname and location).

8 Example INSERT Statement This statement inserts a new row into the DEPT table: DEPTNO value is 50 DNAME value is “DESIGN” LOCATION value is “MIAMI”

9 The SELECT Statement SELECT,, *, … FROM,,, … WHERE, and/or … GROUP BY,, … HAVING and/or … ORDER BY, … The SELECT, and FROM clauses are required. All others are optional.

10 2 tables The EMP table The DEPT table

11 SELECT Statement Example 1 – Simple SELECT select * from DEPT Result: All fields of all rows in the DEPT table

12 SELECT Statement Example 2 – with a filter select * from EMP where ENAME = ‘SMITH’ Result: All fields for employee “Smith”

13 SELECT Statement Example 3 – only 2 cols, and a sort select EMPNO, ENAME from EMP where JOB = ‘SALESMAN’ order by ENAME Result: employee number, name and job for only salesmen from the EMP table, sorted by name

14 What Is a Join Query? A query in which the WHERE clause includes a match of primary key and foreign key values between tables that share a relationship A join could also happen between the values of a unique index of one table and a foreign key of another A join could also be on 2 columns that share the same values, and are not keys (although the join operation would be very inefficient)

15 SELECT Statement Example 4 – Joining 2 tables select EMPNO, ENAME, DNAME from EMP, DEPT where EMP.dept_no = DEPT.dept_no and DEPT.LOC = ‘CHICAGO’; Result: All employees’ number and name (from the EMP table, and their associated department names, obtained by joining the tables based on DEPT_NO. Only employees housed in department located in Chicago will be included

16 SELECT Statement Example 4 (continue) Join queries almost always involve matching the primary key of the dominant (parent) table with the foreign key of the dependent (child) table.

17 What Is an Aggregation Query? A query results in summary information about a group of records, such as sums, counts, or averages These involve using aggregate functions in the SELECT clause such as (SUM, AVG, COUNT, MIN and MAX) Aggregations can be grouped using the GROUP BY clause and can/or can be filtered using the HAVING clause

18 SELECT Statement Example 5 – Using Aggregation select JOB, AVG(SALARY) from EMP group by JOB Select the job category and average salary of employees in the EMP table. Group (sub-total) the result for each JOB category

19 SELECT Statement Example 6 – Filter after Aggregation select JOB, AVG(SALARY) from EMP group by JOB having AVG(SALARY) >= 3000; Only jobs with average salaries exceeding $3000 will be displayed Using Having instead of Where

20 SELECT Statement Example 6 (continue) Note that job categories CLERK and SALESMAN were not included, because the average salaries for these jobs are below $3000.

21 Example Data Manipulation UPDATE EMP set SAL = 3000 where EMPNO = 7698; –Modifies the existing employee’s 7698 salary DELETE from EMP where EMPNO = 7844 –Removes employee 7844 from the EMP table

22 Designing Fields Field – the smallest unit of named data element recognized by system software such as a DBMS Fields map roughly onto attributes in the conceptual data model Field design involves consideration of identity, data types, sizes, and constraints

23 A codification scheme recognized by the software for representing types of data Data Types

24 Considerations for Choosing Data Types Balance these four objectives: 1. Minimize storage space 2. Represent all possible values of the field 3. Improve data integrity for the field 4. Support all data manipulations desired for the field (e.g. mathematical, text)

25 Data Integrity Controls Null Value Controls – determines whether fields can be left empty Default Values – specifies values for fields if no explicit values are entered Range Controls – forces values to be among an acceptable set of values Format Controls – restricts data entry values in specific character positions

26 Data Integrity Controls (cont) Referential Integrity – forces foreign keys to align with primary keys (or other unique indexes) Unique Control – forces each value within the column to be unique Indexing – forces the column to be indexed for faster retrieval

27 Referential integrity is important for ensuring that data relationships are accurate and consistent Referential Integrity Ensures that no value in the cust_order (customer_id) field exists without a corresponding value in customer table.

28 What Is Denormalization? The process of combining columns from various normalized tables into a combined table based on usage and retrieval frequencies Results in better speed of access for SELECT However, reduces data integrity and increases data redundancy

29 This will result in null values for all students who have not applied for a scholarship Example of 1:1 Denormalization

30 This will result in Duplicate regionManager data Example of 1:N Denormalization

31 Example of M:N Denormalization

32 If I combine both Item and CanSupply into CanSupplyDR, this will result in duplication of item descriptions (We’re assuming that an item can be supplied by many different vendors) Example of Denormalization

33 What Is a File Organization? A technique for physically organizing the data in a DBMS. It includes determining tablespace sizes, index sizes, the placement of tables and indexes, etc. Main purpose of file organization which is a DBA function, is to optimize speed of data access and modification

34 What Is Hashing? A technique that uses an algorithm to convert a key value to an memory address Useful for random access, but not for sequential access (e.g. using a phone number) Best suited for densely populated data

35 What Is an Indexed File Organization? A storage structure involving indexes, which are key values and pointers to row addresses Indexed file organizations are structured to enable fast random and sequential access Index files are fast for queries, but require additional overhead for inserts, deletes, and updates

36 Best suited for randomly balanced data. Random Access Using a B-Tree Organization

37 Which Fields should be Indexed? Primary Keys are always indexed Yes No Number of rows in the object Number small?

38 Design of Object Relational Features Object-relational databases support creation of custom data types. (available in recent releases of DBMS) – Composite attributes – Multi-valued attributes – Generalization and inheritance – Aggregation/Composition relationships

39 Allows you to map a composite attribute onto a custom data type Composite Attributes Person_Type is a composite data type, and so is Name_Type and Address_Type Table Employee uses the composite data type

40 Composite Attributes in Oracle 11g Creating Using

41 Composite Attributes in Oracle 11g (Continue) Create table employee ( empid number, emp person_type ); Insert into employee values (123, person_type( name_type(‘Sultan’, ‘Sam’, ‘E’), addr_type(‘123 main street’, ‘New York’, ‘NY’, ‘12345’), ‘01-May-1984’, ‘212-123-1234’) ); Select e.empid, e.emp.name.lastname, e.emp.name.firstname, e.emp.address.street, e.emp.address.city, e.emp.birthdate from employee e

42 Multivalued Attributes in Oracle 11g create type PH_AR as varray(10) of varchar2(15); create table CONTACT ( contactNo number, name varchar2(50), phones PH_AR ); insert into CONTACT values (53, ‘Sam Sultan’, PH_AR(‘212-111-2222’, ‘222-1234’) ); select t1.contactNo, t1.name, t2.column_value from CONTACT t1, table(phones) t2; Use the array Create an array

43 Generalization in Oracle 11g create type EMP_TYPE as object ( empNonumber, empNamevarchar2(50), empAddrvarchar2(100) ) not final; create type HOURLY_TYPE under EMP_TYPE ( hourlyRatenumber ) ; create table HR_EMPLOYEE of HOURLY_TYPE; insert into HR_EMPLOYEE values (100, ‘Sam Sultan’, ‘123 Main St’, 24.50); Create a type as an object Create a subtype Use the subtype Allow for subtype

44 Aggregation/Composition in Oracle 11g create cluster ORDER_CLUSTER ( orderNonumber ) ; create table ORDER_TABLE ( orderNonumber, orderDatedate ) cluster order_cluster (orderNo); create table ORDER_LINE_TABLE ( orderNonumber, productNovarchar2(10), pricenumber, quantitynumber ) cluster order_cluster (orderNo); create index ord_idx on cluster order_cluster; Request a common cluster Index the cluster Create a cluster

45 Recap Af ter studying this chapter we learned to: – The purpose and usage of SQL – Design database fields. – Evaluate denormalization situations. – Design file organization structures. – Design object-relational features.


Download ppt "Chapter 11: Physical Database Design Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph S. Valacich, Jeffrey A. Hoffer."

Similar presentations


Ads by Google