Вы находитесь на странице: 1из 11

Welcome to

SQL
(MISB4304)
‫ﻟﻐﺔ ﺑﻴﺌﺔ ﻗﻮاﻋﺪ اﻟﺒﻴﺎﻧﺎت‬
By
Dr. Romani Farid Ibrahim

2010

Course Overview
† Textbook † Basic Concepts
„ Elmasri, R., Navathe, S., "Fundamentals of
Database Systems", 5th edition, Addison Wesley, Review
2007.

„ Thomas M. Connolly and Carolyn E. Begg † Database design


,“Database Systems: A Practical Approach to
Design, Implementation and Management “, 4th Approaches
edition, Addison Wesley, 200.

† Grading: † Relational Model


Final exam: 40%
„ Internal Assessment: 60%
† SQL
† First exam :20%
† Second exam: 20%
† homeworks and assignments: 20%
2
† E-mail: romanifarid@gmail.com

1
Basic Definitions
† Database: Is a collection of logically related data.
† Data: Known facts that can be recorded and have an implicit meaning. (ex.
Telephone index)
† Database Management System (DBMS): A software system that enables users to
define, create and maintain the database and which provides controlled access
to the database

† Catalog; A DBMS catalog stores the description of a particular database (e.g.


data structures, types, and constraints)
„ The description is called meta-data.

† Database System: database +DBMS +H/W + users


† Database package: DBMS + tools (oracle, access)
† Database administrators (DBA): Responsible for authorizing access to the
database, for coordinating and monitoring its use, acquiring software and hardware
resources, controlling its use and monitoring efficiency of operations.

Example of a simple
database
Student
Name Student_number class Major
Smith 17 1 CS
Brown 8 2 CS

2
Example of a simplified database catalog

Simplified database system environment

3
Typical DBMS Component Modules

Schemas versus Instances


† Database Schema:
„ The description of a database.
„ Includes descriptions of the database structure, data types, and
the constraints on the database.

† Schema Diagram:
„ An illustrative display of database schema.

† Schema Construct:
„ A component of the schema or an object within the schema,
e.g., STUDENT, COURSE.
8

4
Example of a Database Schema

Schemas versus Instances cont.


† Database State (snapshot , instance):
„ The actual data stored in a database at a particular moment in
time. This includes the collection of all the data in the database.
† the content of a database at a moment in time
„ The term instance is also applied to individual database
components, e.g. record instance, table instance, entity instance

† Initial Database State:


„ Refers to the database state when it is initially loaded into the
system.

† Valid State:
„ A state that satisfies the structure and constraints of the
database.

5
Example of a database state

Student
Name Student_number class Major
Smith 17 1 CS
Brown 8 2 CS

11

Implicit Properties of Database


† A database represent some aspect of real world, called the mini-
world or Universe of Discourse (UoD). Changes to the mini-
world are reflected in the database.

† A database is logically coherent collection of data with some


inherent meaning. A random assortment of data cannot correctly
be referred to as a database.

† A database is designed, built, and populated with data for a


specific purpose.

† A database can be of any size and of varying complexity.

† A database may be generated and maintained manually or it may


be computerized. Ex. Library cart catalog.
2

6
Real
World

Facts about world and behaviour of world


represented in
contents and operations of a database

facts about the world in a database more facts some more rather long facts about the world in the databse
facts about the world in a database more facts some more rather long facts about the world in the databse
facts about the world in a database more facts some more rather long facts about the world in the databse
facts about the world in a database more facts some more rather long facts about the world in the databse
facts about the world in a database more facts some more rather long facts about the world in the databse
facts about the world in a database more facts some more rather long facts about the world in the databse

Database
facts about the world in a database more facts
facts about the world in a database
facts about the world in a database
facts about the world in a database
more facts
more facts
more facts
facts about the world in a database
facts about the world in a database
Users
facts about the world in a database facts about the world in a database
facts about the world in a database facts about the world in a database
facts about the world in a database
facts about the world in a database
facts about the world in a database
facts about the world in a database

Three-Schema Architecture

† Defines DBMS schemas at three levels:

„ Internal schema at the internal level to describe physical


storage structures and access paths (e.g indexes).
† Typically uses a physical data model.

„ Conceptual schema at the conceptual level to describe the


structure and constraints for the whole database for a community
of users.
† Uses a conceptual or an implementation data model.

„ External schemas at the external level to describe the various


user views.
† Usually uses the same data model as the conceptual schema. 14

7
The three-schema architecture

15

Database Design

8
Database Design
Customer(CustomerID, Name, Address, …)
SalesPerson(EmployeeID, Name, Commission, … )
Order(OrderID, OrderDate, CustomerID, EmployeeID, … )
OrderItem(OrderID, ItemID, Quantity, Price, … )
Item(ItemID, Description, ListPrice, …)

User views Conceptual Implementation Physical


of data. data model. (relational) data
data model. storage.

Class diagram that List of normalized Indexes and storage


shows business tables. Use data methods to improve
entities, relationships, normalization to derive performance.
and rules. the list.

17

Entity Relationship Model (ER)


† ER model was proposed by Peter Chen in 1976.
† ER model has become the standard tool for conceptual schema
design.
† ER model consists of three basic constructs: entities, attributes
and relationships.

† Entity: is a “thing” in the real world with an independent


existence. It may be an object with physical existence (e.g. person,
car, house, employee), or it may be an object with conceptual
existence (company, job, university, course).
† Entity set: is a collection of entities of the same type.
(e.g. all students of the college) 18

9
Entities types
† Strong entity: can exist independently (or can uniquely identify
itself).

† Weak entity: existence depends on the existence of other


(strong) entity or entities.

„ An employee is a strong entity but the dependents of the


employee could be weak entities.

„ An account in a bank is a strong entity but a transaction


could be a week entity. 19

20

10
Entity Types and Key Attributes
† Key attribute is an attribute whose values are distinct for a given
entity type.
† Every (regular) entity type has at least one key

† Keys may be
„ Simple: one attribute (Stid), or
„ Composite: a set of attributes whose values together
uniquely identify an entity type
† Name(first name, father name, grandfather name, family
name)
† Each key is underlined
„ Person(SSN, Name, Address, Job-description, Salary). 21

Types of Keys
STUDENT(ST-NO, SSN, Name, Age, Address, GPA, Phone-no … )
† Primary Key: a set of one or more attributes that uniquely
identifies entity and it has the following properties:
„ Uniqueness
„ Not Null
„ Minimal
Primary Key: ST-NO
† Candidate key: a subset of attributes which can be used as a
primary key, but it is not chosen.
„ Candidate keys: SSN, ST-NO, Phone-no

† Super Key: a set of one or more attributes that uniquely identifies


entity
Superkey: {ST-No, Name}
{SSN, Age, Address}
{Name, Age, Address}

11

Вам также может понравиться