CIS183: Oracle SQL Programming

Instructor: Rebecca Gottlieb Lecture 1: 2/1/11

Agenda
• • • • • • • • Quiz #0 and Introductions Syllabus Class Website – Oracle Website Lab Development Environment Handout Introduction to Databases! Data Modeling Review In-class Assignment Homework
Copyright 2011 Rebecca Gottlieb

Job Descriptions • • • • • Business Analyst Programmer/Developer Database Administrator Project Manager IT Manager Copyright 2011 Rebecca Gottlieb .

Database Components • • • • • • What is a database? Data? Information? Tables with rows and columns Record Organization: Relational. Object Relational Primary Key Foreign Key Copyright 2011 Rebecca Gottlieb .

Content • • • • • • Single-user database (packaged software) Multi-user database E-Commerce OLTP. CRM. Data Warehouse.Types of Databases: Implementation. Size. ETL. ERP Reporting. OLAP. MRP. Data Mining databases Copyright 2011 Rebecca Gottlieb .

Application Life Cycle • Requirements gathering • Database design (Logical/Physical/App design) • DBMS Creation • Implementation • Data loading • Testing • Operational Maintenance Copyright 2011 Rebecca Gottlieb .

DBMS: Components • Architecture • Users -> application -> DBMS -> db • Application Functions • Display. concurrency • Database – physical. apply business rules • DBMS Functions • information. process queries. DBA activities. hardware. RI constraints Copyright 2011 Rebecca Gottlieb . reports. utilities.

Application Types • Client/Server • eCommerce – web/app server • Reporting applications Copyright 2011 Rebecca Gottlieb .

PL/SQL Schemas.Database • • • • • • • Metadata Data w/Relationships Indexes Code SQL. Users Hardware (the physical representation) Copyright 2011 Rebecca Gottlieb .

Database Design • • • • From existing data From existing database/warehouse/mart New system development Database Design – definition? • Redesign • Analyze the data and business requirements • Create data model using normalization • Create physical database • Migration to new data model • Database consolidation Copyright 2011 Rebecca Gottlieb .

BAD Database Design • • • • • • Forces developers to write complicated code Stores duplicate data Over-denormalization Poorly written SQL – slow response time Sizing issues Data model is unable to accommodate changes to new requirements Copyright 2011 Rebecca Gottlieb .

• It is the basis for the relational database management system (RDBMS). Codd proposed the relational model for database systems in 1970.Relational Database Concept • Dr. • The relational model consists of the following: • Collection of objects or relations • Set of operators to act on the relations • Data integrity for accuracy and consistency Copyright 2011 Rebecca Gottlieb . E. F.

Oracle server Table name: EMPLOYEES Table name: DEPARTMENTS … … Copyright 2011 Rebecca Gottlieb .RDBMS Definition A relational database is a collection of relations or two-dimensional tables.

Data Models Model of system in client’s mind Entity model of client’s model Table model of entity model Oracle server Tables on disk Copyright 2011 Rebecca Gottlieb .

• Determine if each instance of an entity is uniquely identifiable and mark those attributes(s) • Write a short description of each entity • Draw a diagram of each entity and its attributes Copyright 2009 Rebecca Gottlieb .Identifying Entities • Review the business requirements and evaluate each noun to see if it could be an entity • Identify what information about each entity is to be stored. Give each piece of information (attribute) a name (column).

Attribute: • Entity: • Singular. unique name• Singular name • Lowercase • Uppercase • Mandatory marked with “*” • Soft box • Optional marked with “o” • Synonym in parentheses EMPLOYEE #* number * name o job title assigned to composed of DEPARTMENT #* number * name o location Unique Identifier (UID) Primary marked with “#” Secondary marked with “(#)” Copyright 2011 Rebecca Gottlieb .

Each school is located at a specific area of campus and is run by a dean. • A school can not share a dean with another school. or at a location in another school on campus.Identify Entities: Faber College • Faber college is divided into several schools: a school of business. Each dean has a name. and phone number. a school of education. • Each school offers classes to its students. • A dean may teach a class. office number. More than one school can offer the same class. and a school of applied sciences. Each class may be taught in its own school. Copyright 2009 Rebecca Gottlieb . a school of arts and sciences.

Relationships • A relationship is a significant association between one (recursive) or more entities. • Recursive relationships follow the same guidelines as nonrecursive • They are the “verbs” of a diagram • Relationships are bi-directional. If there is a relationship between entity 1 and 2 there must be a relationship between entity 2 and 1 • Relationships are noted with a diamond receives EMPLOYEE supervises Copyright 2009 Rebecca Gottlieb PAYCHECK .

M: child entity • M is the upper bound (max cardinality) for the relationship M:M or M:N (many to many) relationship Relationships are optional if the lower bound is 0 Relationships are mandatory if the lower bound is 1 • • • Copyright 2009 Rebecca Gottlieb .Cardinality • • • • • Maximum: largest amount of instances that can participate in a relationship Minimum: least amount of instances that can participate in a relationship Sets the upper and lower bounds • A class has at least 18 students and a maximum of 40 1:1 (one to one) relationship 1:M (one to many) relationship • The position of the 1 and the M are important. They refer to the entities nearest to them in the diagram • 1: parent entity.

Relating Multiple Tables • Each row of data in a table is uniquely identified by a primary key. Table name: DEPARTMENTS Table name: EMPLOYEES … Primary key Foreign key Primary key Copyright 2011 Rebecca Gottlieb . • You can logically relate data from multiple tables using foreign keys.

Terminology • • • • • • Row Column Primary Key Row w/o Key designation Foreign Key Field with and without data (NULL) Copyright 2011 Rebecca Gottlieb .

g. and the number are different codes? Copyright 2009 Rebecca Gottlieb . USA.Attributes • Attributes provide a piece of information about an entity • Attributes should be assigned to only one entity • Aggregate attributes should be broken down into simple attributes (e. a name should be First Name and Last Name) • Each attribute should have a single value for each instance of an entity • Attributes whose value is derived or calculated from the values of other attributes should not be included in the ER Model • Attributes do not have attributes of their own What is wrong with a key like this: VHSUSA12345 Where VHS.

not null or has a default value • #=unique.Attributes cont. • Attributes are determined from the business information requirements • The attribute names should be easily understood • Names should be singular • Names should be specific: hire_date not h_date • Name should not be an entity name with the exception of a PK or FK reference • Attribute names are listed in the box of their entity in mixed upper case and lower case characters • Determine if each attribute is unique. *=not null Copyright 2009 Rebecca Gottlieb .

oracle.112/e16508/tablecls.com/docs/cd/E11882_01/server.htm#CBBJICEB • HR Schema scripts: $ORACLE_HOME/demo/schema folder Copyright 2011 Rebecca Gottlieb .HR Schema Details • HR Schema ERD http://download.

Database User HR • • This is the schema that is used in this course. and the country code. the company records details such as the country name. In places where the departments and warehouses are located. and each location has a full address that includes the street name. and the region where the country is located geographically. Each department is associated with one location. When an employee resigns. city. state or province. and a minimum and maximum salary range for the job. so it tracks the locations of its warehouses and departments. and manager. salary. currency symbol. the job identification number. the duration the employee was working for. The company also tracks information about jobs within the organization. In the Human Resource (HR) records. job title. job identification code. Each job has an identification code. Some employees earn commissions in addition to their salary. The sample company is regionally diverse. and each department is identified either by a unique department number or a short name. currency name. each employee has an identification number. Some employees have been with the company for a long time and have held different positions within the company. • • Copyright 2009 Rebecca Gottlieb . postal code. Each employee is assigned to a department. email address. and the department are recorded.

and each customer may have many invoices. product price. ABC company maintains its inventory information for each product that it carries. price per item. For each sale. quantity. and the total price of each line. invoice amount.In Class Assignment ABC company sells a variety of products. customer name. and is solely responsible for each invoice that he/she writes. It also maintains information on each vendor for those products. An invoice may only be written for a single customer. and shipping address. Each sales representative may write many invoices. product code and quantity on hand. The information stored on each detail line includes product description. Copyright 2009 Rebecca Gottlieb . an invoice is written up by a sales representative. The information stored on each product includes product description. The information stored on each invoice includes the date. The invoice may contain many detail lines that describe each product purchased by the customer.

) SELECT department_name FROM departments. retrieve. and manipulate data in the tables. easy to learn. Oracle server . you can define.Using SQL to Query Your Database • Structured query language (SQL) is: • The ANSI standard language for operating relational databases • Efficient. and use • Functionally complete (With SQL.

• • • • • • • • • • • • SELECT INSERT UPDATE DELETE MERGE CREATE ALTER DROP RENAME TRUNCATE COMMENT Data manipulation language (DML) Data definition language (DDL) • GRANT • REVOKE Data control language (DCL) • COMMIT • ROLLBACK Transaction control • SAVEPOINT Copyright 2011 Rebecca Gottlieb .

See Oracle Appendix D Copyright 2011 Rebecca Gottlieb .

Sign up to vote on this title
UsefulNot useful