21
CVEV 118/698 CVEV 118/698 Databases Databases Lecture 1 Lecture 1 Prof. Mounir Mabsout Prof. Mounir Mabsout Elsa Sulukdjian Elsa Sulukdjian Walid El Asmar Walid El Asmar

CVEV 118/698 Databases Lecture 1 Prof. Mounir Mabsout Elsa Sulukdjian Walid El Asmar

  • View
    215

  • Download
    0

Embed Size (px)

Citation preview

Page 1: CVEV 118/698 Databases Lecture 1 Prof. Mounir Mabsout Elsa Sulukdjian Walid El Asmar

CVEV 118/698CVEV 118/698DatabasesDatabases

Lecture 1Lecture 1

Prof. Mounir MabsoutProf. Mounir MabsoutElsa SulukdjianElsa SulukdjianWalid El AsmarWalid El Asmar

Page 2: CVEV 118/698 Databases Lecture 1 Prof. Mounir Mabsout Elsa Sulukdjian Walid El Asmar

A database (DB) is an electronic filing A database (DB) is an electronic filing cabinet, a collection of related data cabinet, a collection of related data organized into a list. organized into a list.

Example:Example: list of all VB experts at AUB, with list of all VB experts at AUB, with their name, age and phone number.their name, age and phone number.

Such a list under any electronic format can Such a list under any electronic format can be called a database, I.e. you can construct be called a database, I.e. you can construct a database on MS Excel, Word or even a database on MS Excel, Word or even Notepad as long as it is a collection of Notepad as long as it is a collection of related information. related information.

However the use of a database program, However the use of a database program, such as MS Access, will highly enhance the such as MS Access, will highly enhance the ability to store, manage, find, share, ability to store, manage, find, share, analyze, print, etc… information from your analyze, print, etc… information from your list(s).list(s).

Introduction to Introduction to DatabasesDatabases

Page 3: CVEV 118/698 Databases Lecture 1 Prof. Mounir Mabsout Elsa Sulukdjian Walid El Asmar

DataBase Management DataBase Management SystemSystem

““DBMSDBMS is to a database what a word is to a database what a word processor is to a letter. The former is the processor is to a letter. The former is the controlling, the latter the data that it controlling, the latter the data that it manipulates.” Whitehorn and Marklyn.manipulates.” Whitehorn and Marklyn.

DBMS DBMS are developed for efficient access are developed for efficient access and control of information in databases:and control of information in databases:– Sort and group records.Sort and group records.– Issue complex queries.Issue complex queries.– Managing/Simplifying interactivity to let the user Managing/Simplifying interactivity to let the user concentrate on higher-level issues.concentrate on higher-level issues.

NB:NB: A A queryquery is a question, an inquiry. Queries ask a is a question, an inquiry. Queries ask a question on the information in a list and then retrieve question on the information in a list and then retrieve and display the result, I.e. What projects were already and display the result, I.e. What projects were already corrected by the VB experts?corrected by the VB experts?

Page 4: CVEV 118/698 Databases Lecture 1 Prof. Mounir Mabsout Elsa Sulukdjian Walid El Asmar

DBMS FunctionsDBMS Functions

Functions of Database Management Functions of Database Management Systems:Systems:– Controlling redundancy / sharing of Controlling redundancy / sharing of

data.data.– Restricting unauthorized access.Restricting unauthorized access.– Representing complex relations among Representing complex relations among

data.data.– Enforcing integrity constraints.Enforcing integrity constraints.– Backup and recovery facilities.Backup and recovery facilities.

Page 5: CVEV 118/698 Databases Lecture 1 Prof. Mounir Mabsout Elsa Sulukdjian Walid El Asmar

DBMS HistoryDBMS History

Flat fileFlat file

Proprietary DBMSProprietary DBMS

Relational DBMSRelational DBMS

Page 6: CVEV 118/698 Databases Lecture 1 Prof. Mounir Mabsout Elsa Sulukdjian Walid El Asmar

Flat FileFlat File

Data entries were just lumped in Data entries were just lumped in order into text files. order into text files.

Delimitation was often done by Delimitation was often done by commas or simply spaces. commas or simply spaces.

Associated problems:Associated problems:– ScalabilityScalability– AccuracyAccuracy– ExpandabilityExpandability

Page 7: CVEV 118/698 Databases Lecture 1 Prof. Mounir Mabsout Elsa Sulukdjian Walid El Asmar

Proprietary DBMSProprietary DBMS

Core code originally developed for a Core code originally developed for a general scope. general scope.

Addenda on the core code to adapt Addenda on the core code to adapt to specific projects.to specific projects.

Associated problems:Associated problems:– Integration with other productsIntegration with other products– Ease of usage and efficiency of outputEase of usage and efficiency of output

Page 8: CVEV 118/698 Databases Lecture 1 Prof. Mounir Mabsout Elsa Sulukdjian Walid El Asmar

Relational DBMSRelational DBMS RDBMSRDBMS distinguishes itself by the way data distinguishes itself by the way data

is organized in it in tabulated forms (a is organized in it in tabulated forms (a relation is a table). relation is a table).

RDBMSRDBMS stars: Oracle, MS Access, MS SQL, stars: Oracle, MS Access, MS SQL, Sybase.Sybase.

Terms used:Terms used:– EntityEntity: place, person, event of which you want to : place, person, event of which you want to

keep facts (row, record).keep facts (row, record).– AttributeAttribute: categorized fact of an entity (field, : categorized fact of an entity (field,

column).column).– Entity SetEntity Set: group of entities (table, relation, : group of entities (table, relation,

file).file).

Page 9: CVEV 118/698 Databases Lecture 1 Prof. Mounir Mabsout Elsa Sulukdjian Walid El Asmar

ExampleExample

The order of engineers wants a The order of engineers wants a database that manages engineers, database that manages engineers, universities they graduated from, and universities they graduated from, and the projects they will work on during the projects they will work on during their career.their career.

Page 10: CVEV 118/698 Databases Lecture 1 Prof. Mounir Mabsout Elsa Sulukdjian Walid El Asmar

Example (Cont’d)Example (Cont’d)

Facts to consider:Facts to consider:

– An engineer can graduate from only one An engineer can graduate from only one university.university.

– A university can graduate more than one A university can graduate more than one engineer.engineer.

– A project can have more than one engineer.A project can have more than one engineer.

– An engineer can have more than one An engineer can have more than one project.project.

Page 11: CVEV 118/698 Databases Lecture 1 Prof. Mounir Mabsout Elsa Sulukdjian Walid El Asmar

Example DataExample Data Engineers:Engineers:

Mayon Abou Zeid, AUB, BE, 2001Mayon Abou Zeid, AUB, BE, 2001 Laron Amm, LAU, BE, 2002Laron Amm, LAU, BE, 2002 Rayon Bsat, ESIB, BE, 2003Rayon Bsat, ESIB, BE, 2003

Projects:Projects: TabboulehTabbouleh

– Mayon April 2001 - June 2001Mayon April 2001 - June 2001– Rayon June 2001 – April 2002Rayon June 2001 – April 2002

ChocolateChocolate– Laron October 1997 - June 2001Laron October 1997 - June 2001

KebbehKebbeh– Rayon April 2001 - May 2001Rayon April 2001 - May 2001– Laron September 2001 - April 2002Laron September 2001 - April 2002

Page 12: CVEV 118/698 Databases Lecture 1 Prof. Mounir Mabsout Elsa Sulukdjian Walid El Asmar

DB DesignDB Design

There are many ways to model the There are many ways to model the database of a certain problem such as database of a certain problem such as this example. this example.

Important elements in the design Important elements in the design frame:frame:– Keys.Keys.– Integrity constraints.Integrity constraints.– Relations between tables.Relations between tables.

Page 13: CVEV 118/698 Databases Lecture 1 Prof. Mounir Mabsout Elsa Sulukdjian Walid El Asmar

Primary KeyPrimary Key

Primary key is a field that uniquely references Primary key is a field that uniquely references a record in a table. a record in a table.

In our example, to reference to a certain In our example, to reference to a certain engineer, we need to check his identity by engineer, we need to check his identity by looking at one or several of his attributes; I.e.: looking at one or several of his attributes; I.e.: – Security Number; Family name + Date of birth; Security Number; Family name + Date of birth;

etc.etc. Or we can create a field on its own, usually Or we can create a field on its own, usually

containing numerical values, to provide each containing numerical values, to provide each entry/engineer with a unique identity, I.e. entry/engineer with a unique identity, I.e. ENGID.ENGID.

Page 14: CVEV 118/698 Databases Lecture 1 Prof. Mounir Mabsout Elsa Sulukdjian Walid El Asmar

Primary Key (Cont’d)Primary Key (Cont’d) Creating a primary key (PK) in a table is a Creating a primary key (PK) in a table is a

very encouraged practice, especially when very encouraged practice, especially when dealing with multiple-table databases.dealing with multiple-table databases.

This will help in connecting and managing This will help in connecting and managing information within the project.information within the project.

Thus, in our example, we will most probably Thus, in our example, we will most probably design 3 tables (Engineer, University and design 3 tables (Engineer, University and Project), with a PK each:Project), with a PK each:– Engineer TableEngineer Table ENGIDENGID– University TableUniversity Table UNIVIDUNIVID– Project TableProject Table PJTIDPJTID

Page 15: CVEV 118/698 Databases Lecture 1 Prof. Mounir Mabsout Elsa Sulukdjian Walid El Asmar

RelationshipsRelationships

Relationships among records in DB Relationships among records in DB tables can be any of the following:tables can be any of the following:– One to One 1:1One to One 1:1– One to Many 1:MOne to Many 1:M– Many to Many M:MMany to Many M:M

Page 16: CVEV 118/698 Databases Lecture 1 Prof. Mounir Mabsout Elsa Sulukdjian Walid El Asmar

Relationships in Our Relationships in Our ExampleExample

An engineer can only graduate from An engineer can only graduate from ONEONE university; but a university can have university; but a university can have MANYMANY graduate engineers. Therefore, graduate engineers. Therefore, the relationship between the two records the relationship between the two records is:is:

UniversityUniversity 1 -- Many1 -- Many EngineerEngineer Similarly, we will have the following Similarly, we will have the following

relation for engineers and projects:relation for engineers and projects:

EngineerEngineer Many -- ManyMany -- ManyProjectProject

Page 17: CVEV 118/698 Databases Lecture 1 Prof. Mounir Mabsout Elsa Sulukdjian Walid El Asmar

Foreign Key FKForeign Key FK

It is a field identical in attribute to It is a field identical in attribute to the primary key of another table. the primary key of another table.

I.e. in our example, we can include I.e. in our example, we can include in the Engineer Table a field called in the Engineer Table a field called UNIVID that stores the same values UNIVID that stores the same values as the primary key of the University as the primary key of the University Table. This field is then a Table. This field is then a Foreign Foreign KeyKey..

Page 18: CVEV 118/698 Databases Lecture 1 Prof. Mounir Mabsout Elsa Sulukdjian Walid El Asmar

Entity/Referential Entity/Referential IntegrityIntegrity

A table exhibits A table exhibits Entity IntegrityEntity Integrity if if the the Primary Key:Primary Key:– Is unique for each recordIs unique for each record– ANDAND is NOT NULL is NOT NULL

A database exhibits A database exhibits Referential Referential IntegrityIntegrity if the if the Foreign Key:Foreign Key: Matches the primaryMatches the primary OROR is NULL is NULL

Page 19: CVEV 118/698 Databases Lecture 1 Prof. Mounir Mabsout Elsa Sulukdjian Walid El Asmar

E/R DiagramE/R Diagram

Entity Relationship DiagramEntity Relationship Diagram Widely used to visualize DB DesignWidely used to visualize DB Design TableTable

Engineer

ENGIDENGFNameENGLName

Project

PJTIDPJTName

University

UNVIDUNVName

Page 20: CVEV 118/698 Databases Lecture 1 Prof. Mounir Mabsout Elsa Sulukdjian Walid El Asmar

Example ER DiagramExample ER Diagram

Engineer

ENGIDENGFNameENGLNameUNVIDDegDateDegree

Project

PJTIDPJTName

University

UNVIDUNVName

M1

EngProject

EPTIDENGIDPJTIDStartDateEndDate

M1 M 1

Page 21: CVEV 118/698 Databases Lecture 1 Prof. Mounir Mabsout Elsa Sulukdjian Walid El Asmar

What’s NextWhat’s Next

MS Access Forms, Queries, etc.MS Access Forms, Queries, etc.