Presentation is loading. Please wait.

Presentation is loading. Please wait.

SQL Structured Query Language Programming Course.

Similar presentations


Presentation on theme: "SQL Structured Query Language Programming Course."— Presentation transcript:

1 SQL Structured Query Language Programming Course

2 Eng: Ahmed Aly Saad A Lecturer Assistant Systems & Biomedical Eng. Dept., Faculty of Engineering Cairo University ahmed_saad@gawab.com

3 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

4 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.

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

6 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, Email Servers… Online Library, Email Servers…

7 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

8 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

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

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

11 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.

12 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.

13 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

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

15 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

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

17 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

18 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

19 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

20 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

21 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 1 1 1 N 1N 1 N Location Relationship

22 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 1 1 1 N 1N 1 N hours Start Relationship

23 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)

24 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.

25 Table Example EmployeeFnameLnameSSNAddress AhmedSaad12345Haram AshrafAly33445Mokatem RamyAdel98763Zamalek

26 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

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

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

29 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

30 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

31 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

32 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

33 ? QUESTIONS


Download ppt "SQL Structured Query Language Programming Course."

Similar presentations


Ads by Google