SQL Structured Query Language Programming Course.

Slides:



Advertisements
Similar presentations
Relational Database. Relational database: a set of relations Relation: made up of 2 parts: − Schema : specifies the name of relations, plus name and type.
Advertisements

Relational Databases Chapter 4.
Mapping an ERD to a Relational Database To map an ERD to a relational database, five rules are defined to govern how tables are constructed. 1)Rule for.
Databases and Database Users Sept. 2012Yangjun Chen ACS Outline: Introduction (Chapter 1 – 3 rd, 4 th, 5 th, 6 th ed.) What is a database? The main.
Data modeling using the entity-relationship model Sept. 2012Yangjun Chen ACS Outline: Data modeling using ER-model (Chapter 3 - 3rd, 4th, 5th ed.)
Conceptual Models Agenda - Steps in the design of a DB - Need for conceptual models - The Entity-Relationship Model (ER-Model)
Jyh-haw Yeh Dept. of Computer Science Boise State University
Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Week 3 Outline Overview of Database Design Process Example Database Application (COMPANY) ER Model.
Chapter 4 Relational Databases Copyright © 2012 Pearson Education, Inc. publishing as Prentice Hall 4-1.
Class Number – CS 304 Class Name - DBMS Instructor – Sanjay Madria Instructor – Sanjay Madria Lesson Title – ER Model.
Chapter 4 Relational Databases Copyright © 2012 Pearson Education 4-1.
CS 405G Introduction to Database Systems
Chapter 3 Data Modeling Using the Entity- Relationship (ER) Model Dr. Bernard Chen Ph.D. University of Central Arkansas.
Chapter 3 Relational Model Chapter 4 in Textbook.
Data Modeling Using the Entity-Relationship Model
CSE314 Database Systems Data Modeling Using the Entity- Relationship (ER) Model Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson Ed Slide Set.
1 DATABASE By Mr. Abdalla A. Shaame.  What is a database?  The main characters of a database system  The basic database design method  The entity-relationship.
Information storage: Introduction of database 10/7/2004 Xiangming Mu.
DATABASE MANAGEMENT SYSTEMS BASIC CONCEPTS 1. What is a database? A database is a collection of data which can be used: alone, or alone, or combined /
Logical DB Design 5. 1 CSE2132 Database Systems Week 5 Lecture Logical Database Design.
Database. Basic Definitions Database: A collection of related data. Database Management System (DBMS): A software package/ system to facilitate the creation.
Database. Basic Definitions Database: A collection of related data. Database Management System (DBMS): A software package/ system to facilitate the creation.
RDB/1 An introduction to RDBMS Objectives –To learn about the history and future direction of the SQL standard –To get an overall appreciation of a modern.
Database Technical Session By: Prof. Adarsh Patel.
Introduction to SQL Steve Perry
Introduction to Database Systems
Concepts and Terminology Introduction to Database.
Normalization (Codd, 1972) Practical Information For Real World Database Design.
Chapter 3 Data Modeling Using the Entity- Relationship (ER) Model Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008.
Lecture2: Database Environment Prepared by L. Nouf Almujally & Aisha AlArfaj 1 Ref. Chapter2 College of Computer and Information Sciences - Information.
Chapter 7: Modeling Data in the Organization Dr. Taysir Hassan Abdel Hamid IS Department Faculty of Computer and Information Assiut University March 8,
Relational Database. Database Management System (DBMS)
CIS 210 Systems Analysis and Development Week 6 Part II Designing Databases,
DAY 14: MICROSOFT ACCESS – CHAPTER 1 Madhuri Siddula October 1, 2015.
Initial Design of Entity Types for the COMPANY Database Schema Based on the requirements, we can identify four initial entity types in the COMPANY database:
1 Database & DBMS The data that goes into transaction processing systems (TPS), also goes to a database to be stored and processed later by decision support.
CS 405G: Introduction to Database Systems Lecture 2 : Database Design I.
Database Management COP4540, SCS, FIU Database Modeling Using the Entity-Relationship Model (Continued)
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 7 Data Modeling Using the Entity- Relationship (ER) Model.
Entity-Relationship Model Chapter 3 II COSC 457 Sungchul Hong.
Data Modeling Using the Entity-Relationship (ER) Data Model (Based on Chapter 3 in Fundamentals of Database Systems by Elmasri and Navathe, Ed. 3)
SQL Jan 20,2014. DBMS Stores data as records, tables etc. Accepts data and stores that data for later use Uses query languages for searching, sorting,
Data Modelling Using Entity-Relationship (ER) Model
Foundations of Business Intelligence: Databases and Information Management.
DatabaseIM ISU1 Fundamentals of Database Systems Chapter 3 Data Modeling Using Entity-Relationship Model.
Data Modeling Using the Entity-Relationship (ER) Data Model.
Week 7-8 DBMS ER-Relational Mapping. ER-Relational Mapping.
Chapter 3: Data Modeling Using the Entity-Relationship (ER) Data Model
An Introduction to Database Systems دانشگاه علم و فناوری مازندران - طراحی و ایجاد بانک های اطلاعاتی 1.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 7 Data Modeling Using the Entity- Relationship (ER) Model.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall 1 Chapter 5 (Part a): Logical Database Design and the Relational Model Modern Database Management.
Database Design Chapter 9 Part-1: Concepts & Foreign Keys 1.
Chapter 3: Relational Databases
Howard Paul. Sequential Access Index Files and Data File Random Access.
Conceptual Modelling The Entity-Relationship (ER) Model The ER diagram Data Modelling.
Example COMPANY Database
1 The Relational Data Model David J. Stucki. Relational Model Concepts 2 Fundamental concept: the relation  The Relational Model represents an entire.
Fundamental of Database Systems
CS4222 Principles of Database System
Data Modeling Using the Entity- Relationship (ER) Model
بسم الله الرحمن الرحيم.
Databases and Information Management
CS4222 Principles of Database System
Entity-Relationship Modeling "Extended"
CHAPTER 4: LOGICAL DATABASE DESIGN AND THE RELATIONAL MODEL
Conceptual Data Modeling Using Entities & Relationships
Database Design: Relational Model
Mapping an ERD to a Relational Database
Entity-Relationship Modeling "Extended"
Entity-Relationship Modeling "Extended"
Presentation transcript:

SQL Structured Query Language Programming Course

Eng: Ahmed Aly Saad A Lecturer Assistant Systems & Biomedical Eng. Dept., Faculty of Engineering Cairo University

Course Description Structured Query Language (SQL) is the standard for accessing data in relational databases. Knowing SQL is essential to using products from Microsoft, Oracle, IBM, and other leading companies Structured Query Language (SQL) is the standard for accessing data in relational databases. Knowing SQL is essential to using products from Microsoft, Oracle, IBM, and other leading companies

Course Objectives Relational Database Fundamentals. Relational Database Fundamentals. Database Design & Implementation using SQL server 2000 Database Design & Implementation using SQL server 2000 SQL basics. SQL basics. Use join techniques. Use join techniques. Understand database objects and constraints. Understand database objects and constraints. Write useful SELECT, INSERT, UPDATE. Write useful SELECT, INSERT, UPDATE. and DELETE statements. and DELETE statements.

Today Relational Database Fundamentals Relational Database Fundamentals Database Design & Implementation Database Design & Implementation

Importance of Databases Traditional DB Applications Traditional DB Applications Telephone index, bank, hotel Telephone index, bank, hotel Healthcare Information System (HIS),.. Healthcare Information System (HIS),.. New DB Applications New DB Applications Multimedia DB Geographic Information System (GIS) Data warehouse and Online Analytical Processing (OLAP). Geographic Information System (GIS) Data warehouse and Online Analytical Processing (OLAP). Online Library, Servers… Online Library, Servers…

Definition & Properties Def: Collection of Related Data Represents some aspects of the real world Represents some aspects of the real world (miniworld) (miniworld) Logically Coherent collection of data with some inherent meaning Logically Coherent collection of data with some inherent meaning Designed, built and populated with data for a specific purpose Designed, built and populated with data for a specific purpose

Actors of the Scene Database Administrators Database Administrators Database Designers Database Designers End users End users System Analysts and application programmer System Analysts and application programmer

Different Storage Facilities File Based System File Based System DB based System DB based System

Database Management System (DBMS) Definition. Definition. Types of DBMS. Types of DBMS. How to choose your DBMS. How to choose your DBMS.

Design Problem You are asked to design a database for a company with the following specs. You are asked to design a database for a company with the following specs.

Company Requirements of the Company (oversimplified for illustrative purposes) The company is organized into Departments. Each department has a name, number and an employee who manages the department. We keep track of the start date of the department manager.A department may have several locations. Each department controls a number of Projects. Each project has a name, number and is located at a single location.

Company (Cont.) We store each Employee's name, social security number, address, salary, sex, and birthdate. Each employee works for one department but may work on several projects. We keep track of the number of hours per week that an employee currently works on each project. We also keep track of the direct supervisor of each employee Each employee may have a number of Dependents. For each dependent, we keep track of their name, sex, birthdate, and relationship to employee

Design Steps Step 1: Determine the main Entities Step 1: Determine the main Entities Employee Department DependentProject

Design Steps (Cont.) Step 2: Determine the basic independent attributes for each entity Step 2: Determine the basic independent attributes for each entity Employee Department Dependent Project Name Number Name Number Location Name SSN Address Salary SexBirthdate First Name Sex Birthdate FName Minit LName Location Relationship

Types of Attributes Single versus Composite attributes. Single versus Composite attributes. Single Valued Attributes. Single Valued Attributes. Multi-Valued Attributes Multi-Valued Attributes

Design Steps (Cont.) Step 3: Determine the Primary Key for Each Entity Step 3: Determine the Primary Key for Each Entity Employee Department Dependent Project Name Number Name Number Location Name SSN Address Salary SexBirthdate First Name Sex Birthdate FName Minit LName Location Relationship

Primary Keys and Weak Entities Choice of Primary Key Choice of Primary Key Composite Primary Key Composite Primary Key Definition of Weak Entities Definition of Weak Entities

Design Steps (Cont.) Step 4: Determine the Relationships between different Entities Step 4: Determine the Relationships between different Entities Employee Department Dependent Project Name Number Name Number Location Name SSN Address Salary Sex Birthdate First Name Sex Birthdate FName Minit LName Works For Mange Controls Works_on Dependent of Supervise Location Relationship

Cardinality Ratio One – to – One (mange Relationship) One – to – One (mange Relationship) “each employee manges one department and each department has one manger.” One – to – many ( works_for Relationship) One – to – many ( works_for Relationship) “each employee can work into one department but each department contains of several employees”. Many – to – Many (works_on Relationship) Many – to – Many (works_on Relationship) “each employee works on several projects and each project contains several employees

Design Steps (Cont.) Step 5: Determine the Cardinality ratio for each relationship Step 5: Determine the Cardinality ratio for each relationship Employee Department Dependent Project Name Number Name Number Location Name SSN Address Salary Sex Birthdate First Name Sex Birthdate FName Minit LName Works For Mange Controls Works_on Dependent of Supervise N 1 N M N 1N 1 N Location Relationship

Design Steps (Cont.) Step 6: Determine the attributes of the relationships Step 6: Determine the attributes of the relationships Employee Department Dependent Project Name Number Location Name Number Location Name SSN Address Salary Sex Birthdate First Name Sex Birthdate FName Minit LName Works For Mange Controls Works_on Dependent of Supervise N 1 N M N 1N 1 N hours Start Relationship

Relational Database Terminology Table : a basic structure where in data stored Table : a basic structure where in data stored DB has at least one table DB has at least one table Field : “Column” Field : “Column” (max 1024 fields per table ) (max 1024 fields per table ) Record : “Row” Record : “Row” (no physical limit on the # of rows but the performance is affected) (no physical limit on the # of rows but the performance is affected)

Relational Database Terminology (Cont.) Key : field has a special meaning Key : field has a special meaning Primary key : uniquely identifies a record within a table. Foreign key : establish a relationship between 2 tables “bases of Referential- data integrity”. Other concepts will be discussed later. Other concepts will be discussed later.

Table Example EmployeeFnameLnameSSNAddress AhmedSaad12345Haram AshrafAly33445Mokatem RamyAdel98763Zamalek

Convert ER diagram to Tables In order to implement the ER diagram into any DBMS (i.e. SQL server). We need to convert the ER diagram to Tables In order to implement the ER diagram into any DBMS (i.e. SQL server). We need to convert the ER diagram to Tables

Mapping Rules Rule1: Entity  Table Rule1: Entity  Table Employee Department Project Dependent

Mapping Rules (Cont.) Rule2: simple and composite attribute  Columns Rule2: simple and composite attribute  Columns EmployeeSSNFNameMinitLNameBDateAddressSalarySex ProjectPNumberPNamePLocation DependentDependent_nameSexBirthdateRelationship DepartmentDNumberDName

Mapping Rules (Cont.) Rule3: convert the PKs to PKs into table and the weak entity with P.K and F.K Rule3: convert the PKs to PKs into table and the weak entity with P.K and F.K EmployeeSSNFNameMinitLNameBDateAddressSalarySex ProjectPNumberPNamePLocation DependentDependent_nameESSNSexBirthdateRelationship DepartmentDNumberDName

Mapping Rules (Cont.) Rule 4: multiValue  new Table with F.K Rule 4: multiValue  new Table with F.K Dept_locationsDNumberDLocation DepartmentDNumberDName ProjectPNumberPNamePLocation EmployeeSSNFNameMinitLNameBDateAddressSalarySex DependentDependent_nameESSNSexBirthdateRelationship

Mapping Rules (Cont.) Rule 5: 1-1 and 1- N  F.K in the many table with relationship attributes Rule 5: 1-1 and 1- N  F.K in the many table with relationship attributes Dept_locationsDNumberDLocation DepartmentDNumberDNameMGRSSNMgrStartDate ProjectPNumberPNamePLocationDNUM EmployeeSSNFNameMinitLNameBDateAddressSalarySexSuperSSNDNO DependentDependent_nameESSNSexBirthdateRelationship

Mapping Rules (Cont.) Rule 6: M-N relationship - > new Table with 2 F.K Rule 6: M-N relationship - > new Table with 2 F.K Dept_locationsDNumberDLocation DepartmentDNumberDNameMGRSSNMgrStartDate ProjectPNumberPNamePLocationDNUM EmployeeSSNFNameMinitLNameBDateAddressSalarySexSuperSSNDNO DependentDependent_nameESSNSexBirthdateRelationship Works_OnPNOESSNHours

? QUESTIONS