SlideShare a Scribd company logo
1 of 29
Introduction to SQL

    Fundamentals
      Lesson 1
      COIS 420

       © 2007 Angel G. Diaz
Relational Database System
   • Basic Database Terminology
   • Relational Database Concepts
   • Types of Relationships
   • Types of Keys
   • Integrity Rules
   • Relational Languages




                © 2007 Angel G. Diaz
Basic Terminology

Entity – a person, place, event, or item
Data – facts describing an entity
Attributes – characteristics of an entity
Entity Set – a collection of related entities
Database – a collection of entity sets
Relationship – interaction between entity sets


                © 2007 Angel G. Diaz
Types of Relationships
One-to-one relationship (1:1)
Exists between two entity sets X and Y, if an entity in X has only
one matching entity in Y, and vice versa. For example,
Department and Manager.
One-to-many relationship (1:M)
Exists between two entity sets X and Y, if an entity in X has only
one matching entity in Y, but an entity in Y has many matching
entities in X. For example, Department and Employee.
Many-to-many relationship (M:N)
Exists between two entity sets X and Y, if an entity in X has only
many matching entity in Y, and vice versa. For example, Course
and Student.
                       © 2007 Angel G. Diaz
Database Management System
          (DBMS)
•A software package such as Oracle or IBM DB2.
•Manages data and relationships in the database.
•Creates a Data Dictionary to store Metadata – data about data.
•Manages all day-to-day transactions.
•Provides user with data independence at application level.
•Transforms logical data requests to match physical data structures.
•Secures access through passwords, restricted user access, and encryption.
•Provides backup and recovery mechanisms.
•Provides export and import utilities.
•Allows sharing of data with locking capabilities.

                               © 2007 Angel G. Diaz
Relational Model
Relation – two-dimensional flat table
Tuple – a row or a record
Attribute – a column or a field
Degree – number of attributes in a table
Domain – all possible values of an attribute
Key – a minimal set of attributes used to
uniquely define a row/entity


               © 2007 Angel G. Diaz
Types of Keys
Primary key
A single attribute used as a unique identifier
Composite key
Two or more attributes used as a unique identifier
Secondary key
A non-key attribute used in the search operation
Surrogate key
An added attribute used as a primary key
Foreign key
An attribute that references primary key of a table
                   © 2007 Angel G. Diaz
Integrity Rules
Entity integrity:
        No primary key attribute may have a null value.
        A primary key value must be unique and not null.
        A null value is not known, not entered, not defied, or not
        applicable.
        A space or a zero is not a null value.
Referential integrity:
        A foreign key value may be null.
        A foreign key value must exist as a primary key value in
        another table.
                         © 2007 Angel G. Diaz
Theoretical Relational Languages
   E.F. Codd suggested two theoretical languages with his
   proposed relational model in 1970.


   1. Relational Algebra. A procedural language.
   2. Relational Calculus. A non-procedural language.

   Relational Operations.
       Union            Intersection           Difference
       Selection        Projection             Product
       Join             Assignment             Division

                        © 2007 Angel G. Diaz
Data Modeling

• Database Modeling Techniques
• E-R Diagrams
• Dependency
• Redundancy Problem
• Normal forms
• Normalization


           © 2007 Angel G. Diaz
Data Modeling
Modeling is simplified version of real-life complex
objects.
The Entity-Relationship (E-R) model is a very popular
modeling tool.
The E-R model provides:
   •An excellent communication tool.
   •A simple graphical representation of a database.



                   © 2007 Angel G. Diaz
E-R Diagram
•An entity (or entity set) is represented by a rectangle. The name of the entity is
written within the rectangle in a singular upper-case noun. For example,
EMPLOYEE.
•The relationship between two entity sets is represented in a diamond-shaped
box. The name of relationship is an active verb in lower-case. For example,
supervises.
•The types of relationship is called connectivity.
•The lower and upper limit of relationship is called cardinality.
•The optional relationship is shown with a small circle next to the optional
entity.
•The decomposition of a M:N relationship into two 1:M relationships involves a
third composite entity, which is shown with a diamond in a rectangle.
•The weak entities, which cannot exist by themselves, are shown with double-
lined rectangles.
                               © 2007 Angel G. Diaz
Types of Attributes
Simple Attribute.
Attribute that cannot be subdivided. For example, city, gender, or last name.

Composite Attribute.
Attribute that can be sub divided. For example, name or mailing address.

Single-valued Attribute.
Attribute with a single-value per entity. For example, first name or employee
number.

Multi-valued Attribute.
Attribute with multiple values per entity. For example, student’s courses.


                             © 2007 Angel G. Diaz
Table with Multi-valued Attributes
InvNo   InvDate    CustNo   ItemNo            Cust      Item     Item        Qty
                                              Name      Name     Price
1001    04/14/00   212      1               Starks     Screw    $2.25    5


                            3                          Bolt     $3.99    5

                            5                          Washer   $1.99    9

1002    04/17/00   225      1               Connors    Screw    $2.25    2


                            2                          Nut      $5.00    3

1003    04/17/00   239      1               Kapur      Screw    $2.25    7


                            2                          Nut      $5.00    1

1004    04/18/00   211      4               Garcia     Hammer   $9.99    5




                                © 2007 Angel G. Diaz
Dependencies
The primary key describes an entity.
The non-key attributes are functionally dependent on he primary
key attribute(s).

                  Types of Dependencies
Total – a non-key attribute is totally dependent on primary key
attributes.
Partial – a non-key attribute is dependent on part of the primary
key.
Transitive – a non-key attribute is dependent on another non-key
attribute.


                        © 2007 Angel G. Diaz
Redundancy
Redundancy means
• Repeated data entry.
• Repeated changes in many places.
• More storage space.
• Deletion anomaly – deletion of one entity results in
deletion of another entity.
• Insertion anomaly – Insertion of one entity depends on
information about another entity.

                        © 2007 Angel G. Diaz
Normal Forms
First Normal Form (1NF)
   •Table’s primary key is defined.
   •All non-key attributes show functional dependency on the primary key
   components.
   •Table does not contain multi-valued attributes.
Second Normal Form (2NF)
   •All 1NF requirements are satisfied.
   •There is no partial dependency.
Third Normal Form (3NF)
   •All 2NF requirements are fulfilled.
   •There is no transitive dependency.
                             © 2007 Angel G. Diaz
INVOICE Table in 1NF
InvNo   InvDate    CustNo   ItemNo         CustName    ItemName   ItemPrice   Qty

1001    04/14/00   212      1             Starks       Screw      $2.25       5

1001    04/14/00   212      3             Starks       Bolt       $3.99       5

1001    04/14/00   212      5             Starks       Washer     $1.99       9

1002    04/17/00   225      1             Connors      Screw      $2.25       2

1002    04/17/00   225      2             Connors      Nut        $5.00       3

1003    04/17/00   239      1             Kapur        Screw      $2.25       7

1003    04/17/00   239      2             Kapur        Nut        $5.00       1

1004    04/18/00   211      4             Garcia       Hammer     $9.99       5



 Attributes InvDate, CustNo and CustName are partially dependent on InvNo.
 Attributes ItemName and ItemPrice are partially dependent on ItemNo.
 Attribute Qty is totally dependent on InvNo and ItemNo.
 Attribute CustName shows transitive dependency on CustNo.
                                © 2007 Angel G. Diaz
Normalization

• A process of decomposing a table into many tables.
    • A process to increase table’s normal form.
         • A process to reduce redundancy.



  The higher the normal form is,
      the lower the redundancy.
                  © 2007 Angel G. Diaz
1NF to 2NF
(Removal of partial dependencies)
•Write each primary key component (with partial dependency on it)
on a separate line.
•Write composite key on the next line.


INVOICE table decomposed into 2NF:
INV (InvNo, InvDate, CustNo, CustName)
ITEM (ItemNo, ItemName, ItemPrice)
INVITEM (InvNo, ItemNo, Qty)

                        © 2007 Angel G. Diaz
2NF to 3NF
         (Removal of transitive dependencies)
•Move attributes with transitive dependency to a new table.
•Keep the primary key of the new table as the foreign key in the
existing table.

Database in 3NF:
    INV (InvNo, InvDate, CustNo)
    CUSTOMER (CustNo, CustName)
    ITEM (ItemNo, ItemName, ItemPrice)
    INVITEM (InvNo, ItemNo, Qty)


                         © 2007 Angel G. Diaz
Database Tools

• Personal Databases
• Client/Server Databases
• Oracle and its Tools
• Types of SQL Statements




          © 2007 Angel G. Diaz
Personal Databases
• Usually stored on a client computer
• Primarily for single-user applications
• Stored on a server for multi-user or shared access
• A server is a computer that accepts and services
  requests from clients. A server’s resources include hard
  disk, programs, data, or printers.
• For example, Microsoft-Access and Visual Fox Pro



                        © 2007 Angel G. Diaz
Characteristics of a
    Personal Database System
• Heavy traffic on network to transport applications and
  databases between server and clients
• Heavy demand on Client computer
• Inferior system response time
• No automatic table locking, but optimistic locking
• Client failure may result in record locking and database
  corruption
• Transaction log kept in client’s memory

                       © 2007 Angel G. Diaz
Client/Server Databases
• Usually stored on the server computer
• Primarily for multi-user applications
• Allows shared-access with locking
• An Oracle server accepts and services requests
  from clients.
• The client computer does not contain database
  and does not perform any processing
• For example, Oracle, DB2, SAP, etc.

                   © 2007 Angel G. Diaz
Characteristics of a
Client/Server Database System
• Low network traffic as only client requests and
  results are transported
• Low demand on client as server processes requests
• Automatic locking
• If a client fails, other clients not affected
• Central Transaction Log kept on server
• If a batch transaction fails, entire transaction is rolled
  back

                        © 2007 Angel G. Diaz
Oracle and its Tools
• A Client/Server database system
• A object-relational database system
• Oracle Corp is the second largest software company in the world
                                      Tools
SQL*Plus – environment to write command-line SQL queries
PL/SQL – Oracle’s procedural language extension to SQL
Query Builder – graphical environment for SQL query building
Developer – Form Builder, Report Builder, Graphic Builder
Enterprise Manager – a tool to manage database and users. For example, Storage
Manager, Instance Manager and Security Manager
Oracle Web Application Server – to access Oracle databases through web pages


                                 © 2007 Angel G. Diaz
Structured Query Language (SQL)
 • Universal query language for relational databases
 • Standardized and accepted by ANSI and ISO
 • A non-procedural, fourth generation, high-level language
                                Types of SQL statements

 Data Definition Language (DDL) – creates, changes, removes table’s structure
 For example, CREATE, ALTER, DROP, RENAME, and TRUNCATE
 Data Manipulation Language (DML) – inserts, changes and removes rows
 For example, INSERT, UPDATE, and DELETE
 Data Retrieval – retrieves data from database, For example, SELECT
 Transaction Control Language (TCL) – manages logical transactions
 For example, COMMIT, SAVEPOINT, and ROLLBACK
 Data Control Language (DCL) – gives and removes rights to objects
 For example, GRANT and REVOKE
                                     © 2007 Angel G. Diaz
End of Lesson 1




     © 2007 Angel G. Diaz

More Related Content

Viewers also liked

گزارش کار آزمایشگاه مدارهای الکنریکی
گزارش کار آزمایشگاه مدارهای الکنریکیگزارش کار آزمایشگاه مدارهای الکنریکی
گزارش کار آزمایشگاه مدارهای الکنریکیtahereh sharafi
 
Cancer de pulmon de celulas pequeñas
Cancer de pulmon de celulas pequeñasCancer de pulmon de celulas pequeñas
Cancer de pulmon de celulas pequeñaseddynoy velasquez
 
Poemas paz en galego primaria
Poemas paz en galego primariaPoemas paz en galego primaria
Poemas paz en galego primariacrocaio
 
Best Artist Rep Magazine August 2016 Issue
Best Artist Rep Magazine August 2016 IssueBest Artist Rep Magazine August 2016 Issue
Best Artist Rep Magazine August 2016 IssueSteven Michael Jennings
 
Informatica juridica metadocumental y metadesicional
Informatica juridica metadocumental y metadesicionalInformatica juridica metadocumental y metadesicional
Informatica juridica metadocumental y metadesicionalvane sandoval
 
Clase de integracion clinica imagenes en abdomen
Clase de integracion clinica imagenes en abdomenClase de integracion clinica imagenes en abdomen
Clase de integracion clinica imagenes en abdomenMétodos Digitales - UBA
 
Electra Heart: Um retrato do Sonho Americano por meio dos arquétipos do álbum...
Electra Heart: Um retrato do Sonho Americano por meio dos arquétipos do álbum...Electra Heart: Um retrato do Sonho Americano por meio dos arquétipos do álbum...
Electra Heart: Um retrato do Sonho Americano por meio dos arquétipos do álbum...Danielle Katrine
 
Lesson - 02 Network Design and Management
Lesson - 02 Network Design and ManagementLesson - 02 Network Design and Management
Lesson - 02 Network Design and ManagementAngel G Diaz
 
1Z0-052 Oracle 11g Administration I
1Z0-052 Oracle 11g Administration I1Z0-052 Oracle 11g Administration I
1Z0-052 Oracle 11g Administration IRemote DBA Services
 

Viewers also liked (19)

Tarea N° 5
Tarea N° 5Tarea N° 5
Tarea N° 5
 
گزارش کار آزمایشگاه مدارهای الکنریکی
گزارش کار آزمایشگاه مدارهای الکنریکیگزارش کار آزمایشگاه مدارهای الکنریکی
گزارش کار آزمایشگاه مدارهای الکنریکی
 
Best Artist Rep Magazine June 2016
Best Artist Rep Magazine June 2016Best Artist Rep Magazine June 2016
Best Artist Rep Magazine June 2016
 
Cancer de pulmon de celulas pequeñas
Cancer de pulmon de celulas pequeñasCancer de pulmon de celulas pequeñas
Cancer de pulmon de celulas pequeñas
 
Poemas paz en galego primaria
Poemas paz en galego primariaPoemas paz en galego primaria
Poemas paz en galego primaria
 
Best Artist Rep Magazine August 2016 Issue
Best Artist Rep Magazine August 2016 IssueBest Artist Rep Magazine August 2016 Issue
Best Artist Rep Magazine August 2016 Issue
 
Informatica juridica metadocumental y metadesicional
Informatica juridica metadocumental y metadesicionalInformatica juridica metadocumental y metadesicional
Informatica juridica metadocumental y metadesicional
 
Clase de informática básica
Clase de informática básicaClase de informática básica
Clase de informática básica
 
Clase de tomografía computada
Clase de tomografía computada Clase de tomografía computada
Clase de tomografía computada
 
Clase de integracion clinica imagenes en abdomen
Clase de integracion clinica imagenes en abdomenClase de integracion clinica imagenes en abdomen
Clase de integracion clinica imagenes en abdomen
 
Clase de integracion clinica mama 2016
Clase de integracion clinica mama 2016Clase de integracion clinica mama 2016
Clase de integracion clinica mama 2016
 
Electra Heart: Um retrato do Sonho Americano por meio dos arquétipos do álbum...
Electra Heart: Um retrato do Sonho Americano por meio dos arquétipos do álbum...Electra Heart: Um retrato do Sonho Americano por meio dos arquétipos do álbum...
Electra Heart: Um retrato do Sonho Americano por meio dos arquétipos do álbum...
 
Neumonía: Manejo DIagnóstico y Terapeutico
Neumonía:  Manejo DIagnóstico y TerapeuticoNeumonía:  Manejo DIagnóstico y Terapeutico
Neumonía: Manejo DIagnóstico y Terapeutico
 
Cuello (OTORRINOLARINGOLOGIA)
Cuello (OTORRINOLARINGOLOGIA)Cuello (OTORRINOLARINGOLOGIA)
Cuello (OTORRINOLARINGOLOGIA)
 
CARCINOMA BASOCELULAR
CARCINOMA BASOCELULARCARCINOMA BASOCELULAR
CARCINOMA BASOCELULAR
 
Lesson - 02 Network Design and Management
Lesson - 02 Network Design and ManagementLesson - 02 Network Design and Management
Lesson - 02 Network Design and Management
 
1Z0-052 Oracle 11g Administration I
1Z0-052 Oracle 11g Administration I1Z0-052 Oracle 11g Administration I
1Z0-052 Oracle 11g Administration I
 
Rayos x de torax
Rayos x de torax Rayos x de torax
Rayos x de torax
 
Leischmaniasis (Kala Azar)
Leischmaniasis (Kala Azar)Leischmaniasis (Kala Azar)
Leischmaniasis (Kala Azar)
 

More from Angel G Diaz

SQL Developer installation-guide
SQL Developer installation-guideSQL Developer installation-guide
SQL Developer installation-guideAngel G Diaz
 
Lesson 01 - Network Assessment
Lesson 01 - Network AssessmentLesson 01 - Network Assessment
Lesson 01 - Network AssessmentAngel G Diaz
 
OracleXE & SQLDeveloper Install
OracleXE & SQLDeveloper InstallOracleXE & SQLDeveloper Install
OracleXE & SQLDeveloper InstallAngel G Diaz
 
GNS3 Simulator Installation
GNS3 Simulator InstallationGNS3 Simulator Installation
GNS3 Simulator InstallationAngel G Diaz
 
WAMP & Joomla! Installation
WAMP & Joomla! InstallationWAMP & Joomla! Installation
WAMP & Joomla! InstallationAngel G Diaz
 
COIS 420 - Practice04
COIS 420 - Practice04COIS 420 - Practice04
COIS 420 - Practice04Angel G Diaz
 
COIS 420 - Practice 03
COIS 420 - Practice 03COIS 420 - Practice 03
COIS 420 - Practice 03Angel G Diaz
 
COIS 420 - Practice02
COIS 420 - Practice02COIS 420 - Practice02
COIS 420 - Practice02Angel G Diaz
 
COIS 420 - Practice01
COIS 420 - Practice01COIS 420 - Practice01
COIS 420 - Practice01Angel G Diaz
 
Lesson02 - Network Design & LAN
Lesson02 - Network Design & LANLesson02 - Network Design & LAN
Lesson02 - Network Design & LANAngel G Diaz
 
Errors, Error Detection, and Error Control
Errors, Error Detection, and Error ControlErrors, Error Detection, and Error Control
Errors, Error Detection, and Error ControlAngel G Diaz
 
Errors, Error Detection, and Error Control
Errors, Error Detection, and Error ControlErrors, Error Detection, and Error Control
Errors, Error Detection, and Error ControlAngel G Diaz
 
Making Connections Efficient: Multiplexing and Compression
Making Connections Efficient: Multiplexing and CompressionMaking Connections Efficient: Multiplexing and Compression
Making Connections Efficient: Multiplexing and CompressionAngel G Diaz
 
Making Connections
Making ConnectionsMaking Connections
Making ConnectionsAngel G Diaz
 
Conducted and Wireless Media
Conducted and Wireless MediaConducted and Wireless Media
Conducted and Wireless MediaAngel G Diaz
 
Fundamentals of Data and Signals
Fundamentals of Data and SignalsFundamentals of Data and Signals
Fundamentals of Data and SignalsAngel G Diaz
 
Introduction to Computer Networks and Data Communications
Introduction to Computer Networks and Data CommunicationsIntroduction to Computer Networks and Data Communications
Introduction to Computer Networks and Data CommunicationsAngel G Diaz
 

More from Angel G Diaz (18)

SQL Developer installation-guide
SQL Developer installation-guideSQL Developer installation-guide
SQL Developer installation-guide
 
Lesson 01 - Network Assessment
Lesson 01 - Network AssessmentLesson 01 - Network Assessment
Lesson 01 - Network Assessment
 
OracleXE & SQLDeveloper Install
OracleXE & SQLDeveloper InstallOracleXE & SQLDeveloper Install
OracleXE & SQLDeveloper Install
 
GNS3 Simulator Installation
GNS3 Simulator InstallationGNS3 Simulator Installation
GNS3 Simulator Installation
 
WAMP & Joomla! Installation
WAMP & Joomla! InstallationWAMP & Joomla! Installation
WAMP & Joomla! Installation
 
COIS 420 - Practice04
COIS 420 - Practice04COIS 420 - Practice04
COIS 420 - Practice04
 
COIS 420 - Practice 03
COIS 420 - Practice 03COIS 420 - Practice 03
COIS 420 - Practice 03
 
COIS 420 - Practice02
COIS 420 - Practice02COIS 420 - Practice02
COIS 420 - Practice02
 
COIS 420 - Practice01
COIS 420 - Practice01COIS 420 - Practice01
COIS 420 - Practice01
 
Lesson02 - Network Design & LAN
Lesson02 - Network Design & LANLesson02 - Network Design & LAN
Lesson02 - Network Design & LAN
 
Errors, Error Detection, and Error Control
Errors, Error Detection, and Error ControlErrors, Error Detection, and Error Control
Errors, Error Detection, and Error Control
 
Errors, Error Detection, and Error Control
Errors, Error Detection, and Error ControlErrors, Error Detection, and Error Control
Errors, Error Detection, and Error Control
 
Making Connections Efficient: Multiplexing and Compression
Making Connections Efficient: Multiplexing and CompressionMaking Connections Efficient: Multiplexing and Compression
Making Connections Efficient: Multiplexing and Compression
 
Making Connections
Making ConnectionsMaking Connections
Making Connections
 
Conducted and Wireless Media
Conducted and Wireless MediaConducted and Wireless Media
Conducted and Wireless Media
 
Fundamentals of Data and Signals
Fundamentals of Data and SignalsFundamentals of Data and Signals
Fundamentals of Data and Signals
 
Introduction to Computer Networks and Data Communications
Introduction to Computer Networks and Data CommunicationsIntroduction to Computer Networks and Data Communications
Introduction to Computer Networks and Data Communications
 
Cois240 lesson01
Cois240 lesson01Cois240 lesson01
Cois240 lesson01
 

Recently uploaded

Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxNikitaBankoti2
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesShubhangi Sonawane
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 

Recently uploaded (20)

Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Role Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptxRole Of Transgenic Animal In Target Validation-1.pptx
Role Of Transgenic Animal In Target Validation-1.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 

Lesson 01 - Introduction to SQL

  • 1. Introduction to SQL Fundamentals Lesson 1 COIS 420 © 2007 Angel G. Diaz
  • 2. Relational Database System • Basic Database Terminology • Relational Database Concepts • Types of Relationships • Types of Keys • Integrity Rules • Relational Languages © 2007 Angel G. Diaz
  • 3. Basic Terminology Entity – a person, place, event, or item Data – facts describing an entity Attributes – characteristics of an entity Entity Set – a collection of related entities Database – a collection of entity sets Relationship – interaction between entity sets © 2007 Angel G. Diaz
  • 4. Types of Relationships One-to-one relationship (1:1) Exists between two entity sets X and Y, if an entity in X has only one matching entity in Y, and vice versa. For example, Department and Manager. One-to-many relationship (1:M) Exists between two entity sets X and Y, if an entity in X has only one matching entity in Y, but an entity in Y has many matching entities in X. For example, Department and Employee. Many-to-many relationship (M:N) Exists between two entity sets X and Y, if an entity in X has only many matching entity in Y, and vice versa. For example, Course and Student. © 2007 Angel G. Diaz
  • 5. Database Management System (DBMS) •A software package such as Oracle or IBM DB2. •Manages data and relationships in the database. •Creates a Data Dictionary to store Metadata – data about data. •Manages all day-to-day transactions. •Provides user with data independence at application level. •Transforms logical data requests to match physical data structures. •Secures access through passwords, restricted user access, and encryption. •Provides backup and recovery mechanisms. •Provides export and import utilities. •Allows sharing of data with locking capabilities. © 2007 Angel G. Diaz
  • 6. Relational Model Relation – two-dimensional flat table Tuple – a row or a record Attribute – a column or a field Degree – number of attributes in a table Domain – all possible values of an attribute Key – a minimal set of attributes used to uniquely define a row/entity © 2007 Angel G. Diaz
  • 7. Types of Keys Primary key A single attribute used as a unique identifier Composite key Two or more attributes used as a unique identifier Secondary key A non-key attribute used in the search operation Surrogate key An added attribute used as a primary key Foreign key An attribute that references primary key of a table © 2007 Angel G. Diaz
  • 8. Integrity Rules Entity integrity: No primary key attribute may have a null value. A primary key value must be unique and not null. A null value is not known, not entered, not defied, or not applicable. A space or a zero is not a null value. Referential integrity: A foreign key value may be null. A foreign key value must exist as a primary key value in another table. © 2007 Angel G. Diaz
  • 9. Theoretical Relational Languages E.F. Codd suggested two theoretical languages with his proposed relational model in 1970. 1. Relational Algebra. A procedural language. 2. Relational Calculus. A non-procedural language. Relational Operations. Union Intersection Difference Selection Projection Product Join Assignment Division © 2007 Angel G. Diaz
  • 10. Data Modeling • Database Modeling Techniques • E-R Diagrams • Dependency • Redundancy Problem • Normal forms • Normalization © 2007 Angel G. Diaz
  • 11. Data Modeling Modeling is simplified version of real-life complex objects. The Entity-Relationship (E-R) model is a very popular modeling tool. The E-R model provides: •An excellent communication tool. •A simple graphical representation of a database. © 2007 Angel G. Diaz
  • 12. E-R Diagram •An entity (or entity set) is represented by a rectangle. The name of the entity is written within the rectangle in a singular upper-case noun. For example, EMPLOYEE. •The relationship between two entity sets is represented in a diamond-shaped box. The name of relationship is an active verb in lower-case. For example, supervises. •The types of relationship is called connectivity. •The lower and upper limit of relationship is called cardinality. •The optional relationship is shown with a small circle next to the optional entity. •The decomposition of a M:N relationship into two 1:M relationships involves a third composite entity, which is shown with a diamond in a rectangle. •The weak entities, which cannot exist by themselves, are shown with double- lined rectangles. © 2007 Angel G. Diaz
  • 13. Types of Attributes Simple Attribute. Attribute that cannot be subdivided. For example, city, gender, or last name. Composite Attribute. Attribute that can be sub divided. For example, name or mailing address. Single-valued Attribute. Attribute with a single-value per entity. For example, first name or employee number. Multi-valued Attribute. Attribute with multiple values per entity. For example, student’s courses. © 2007 Angel G. Diaz
  • 14. Table with Multi-valued Attributes InvNo InvDate CustNo ItemNo Cust Item Item Qty Name Name Price 1001 04/14/00 212 1 Starks Screw $2.25 5 3 Bolt $3.99 5 5 Washer $1.99 9 1002 04/17/00 225 1 Connors Screw $2.25 2 2 Nut $5.00 3 1003 04/17/00 239 1 Kapur Screw $2.25 7 2 Nut $5.00 1 1004 04/18/00 211 4 Garcia Hammer $9.99 5 © 2007 Angel G. Diaz
  • 15. Dependencies The primary key describes an entity. The non-key attributes are functionally dependent on he primary key attribute(s). Types of Dependencies Total – a non-key attribute is totally dependent on primary key attributes. Partial – a non-key attribute is dependent on part of the primary key. Transitive – a non-key attribute is dependent on another non-key attribute. © 2007 Angel G. Diaz
  • 16. Redundancy Redundancy means • Repeated data entry. • Repeated changes in many places. • More storage space. • Deletion anomaly – deletion of one entity results in deletion of another entity. • Insertion anomaly – Insertion of one entity depends on information about another entity. © 2007 Angel G. Diaz
  • 17. Normal Forms First Normal Form (1NF) •Table’s primary key is defined. •All non-key attributes show functional dependency on the primary key components. •Table does not contain multi-valued attributes. Second Normal Form (2NF) •All 1NF requirements are satisfied. •There is no partial dependency. Third Normal Form (3NF) •All 2NF requirements are fulfilled. •There is no transitive dependency. © 2007 Angel G. Diaz
  • 18. INVOICE Table in 1NF InvNo InvDate CustNo ItemNo CustName ItemName ItemPrice Qty 1001 04/14/00 212 1 Starks Screw $2.25 5 1001 04/14/00 212 3 Starks Bolt $3.99 5 1001 04/14/00 212 5 Starks Washer $1.99 9 1002 04/17/00 225 1 Connors Screw $2.25 2 1002 04/17/00 225 2 Connors Nut $5.00 3 1003 04/17/00 239 1 Kapur Screw $2.25 7 1003 04/17/00 239 2 Kapur Nut $5.00 1 1004 04/18/00 211 4 Garcia Hammer $9.99 5 Attributes InvDate, CustNo and CustName are partially dependent on InvNo. Attributes ItemName and ItemPrice are partially dependent on ItemNo. Attribute Qty is totally dependent on InvNo and ItemNo. Attribute CustName shows transitive dependency on CustNo. © 2007 Angel G. Diaz
  • 19. Normalization • A process of decomposing a table into many tables. • A process to increase table’s normal form. • A process to reduce redundancy. The higher the normal form is, the lower the redundancy. © 2007 Angel G. Diaz
  • 20. 1NF to 2NF (Removal of partial dependencies) •Write each primary key component (with partial dependency on it) on a separate line. •Write composite key on the next line. INVOICE table decomposed into 2NF: INV (InvNo, InvDate, CustNo, CustName) ITEM (ItemNo, ItemName, ItemPrice) INVITEM (InvNo, ItemNo, Qty) © 2007 Angel G. Diaz
  • 21. 2NF to 3NF (Removal of transitive dependencies) •Move attributes with transitive dependency to a new table. •Keep the primary key of the new table as the foreign key in the existing table. Database in 3NF: INV (InvNo, InvDate, CustNo) CUSTOMER (CustNo, CustName) ITEM (ItemNo, ItemName, ItemPrice) INVITEM (InvNo, ItemNo, Qty) © 2007 Angel G. Diaz
  • 22. Database Tools • Personal Databases • Client/Server Databases • Oracle and its Tools • Types of SQL Statements © 2007 Angel G. Diaz
  • 23. Personal Databases • Usually stored on a client computer • Primarily for single-user applications • Stored on a server for multi-user or shared access • A server is a computer that accepts and services requests from clients. A server’s resources include hard disk, programs, data, or printers. • For example, Microsoft-Access and Visual Fox Pro © 2007 Angel G. Diaz
  • 24. Characteristics of a Personal Database System • Heavy traffic on network to transport applications and databases between server and clients • Heavy demand on Client computer • Inferior system response time • No automatic table locking, but optimistic locking • Client failure may result in record locking and database corruption • Transaction log kept in client’s memory © 2007 Angel G. Diaz
  • 25. Client/Server Databases • Usually stored on the server computer • Primarily for multi-user applications • Allows shared-access with locking • An Oracle server accepts and services requests from clients. • The client computer does not contain database and does not perform any processing • For example, Oracle, DB2, SAP, etc. © 2007 Angel G. Diaz
  • 26. Characteristics of a Client/Server Database System • Low network traffic as only client requests and results are transported • Low demand on client as server processes requests • Automatic locking • If a client fails, other clients not affected • Central Transaction Log kept on server • If a batch transaction fails, entire transaction is rolled back © 2007 Angel G. Diaz
  • 27. Oracle and its Tools • A Client/Server database system • A object-relational database system • Oracle Corp is the second largest software company in the world Tools SQL*Plus – environment to write command-line SQL queries PL/SQL – Oracle’s procedural language extension to SQL Query Builder – graphical environment for SQL query building Developer – Form Builder, Report Builder, Graphic Builder Enterprise Manager – a tool to manage database and users. For example, Storage Manager, Instance Manager and Security Manager Oracle Web Application Server – to access Oracle databases through web pages © 2007 Angel G. Diaz
  • 28. Structured Query Language (SQL) • Universal query language for relational databases • Standardized and accepted by ANSI and ISO • A non-procedural, fourth generation, high-level language Types of SQL statements Data Definition Language (DDL) – creates, changes, removes table’s structure For example, CREATE, ALTER, DROP, RENAME, and TRUNCATE Data Manipulation Language (DML) – inserts, changes and removes rows For example, INSERT, UPDATE, and DELETE Data Retrieval – retrieves data from database, For example, SELECT Transaction Control Language (TCL) – manages logical transactions For example, COMMIT, SAVEPOINT, and ROLLBACK Data Control Language (DCL) – gives and removes rights to objects For example, GRANT and REVOKE © 2007 Angel G. Diaz
  • 29. End of Lesson 1 © 2007 Angel G. Diaz