SlideShare uma empresa Scribd logo
1 de 59
SQL Concepts
Course:-MCA -II
Subject:-Database Management System
Unit:-3
1
Entity-Relationship(ER) Model
 The ER model is a high-level conceptual data model.
It has not been implemented in any commercial
DBMS (?), but is a powerful short hand often used in
database design for a first rendition of the miniworld.
 The ER model was introduced by Peter Chen in 1976,
and is now the most widely used conceptual data
model.
2
Entity-Relationship(ER) Model[1]
3
Definitions
 An entity is an object in the miniworld.
 An attribute of an entity can have a value from a
value set (domain)
 Each entity belongs to some one entity type s.t.
entities in one entity type have the same attributes (so
each entity type is a set of similar entities).
4
Definitions
 A key attribute of an entity type is one whose value
uniquely identifies an entity of that type.
 A combination of attributes may form a composite
key.
 If there is no applicable value for an attribute that
attribute is set to a null value.
5
6
Entity Type / Entity Set
Entity Type (Intension): EMPLOYEE
Attributes: Name, Age, Salary
Entity Set (Extension): e1 = (John Smith, 55, 80000)
e2 = (Joe Doe, 40, 20000)
e3 = (Jane Doe, 27, 30000)
.
.
.
Attributes
 Attributes can be
 composite / simple (atomic)
 single-valued / multivalued
 stored / derived
 key / nonkey.
7
Attribute Examples
8
Name = John Doe
Birth date = May 10, 1989
Age = 9
Degree = null
SSN = 123456789
Name = John Doe
Birth date = May 10
Birth year = 1989
Age = 9
Degree = null
SSN = 123456789
Name = Jane Doe
Birthrate = July 11, 1960
Age = 38
Degree = B.S., M.S.
SSN = 987654321
Symbols
9
10
EMPLOYEE
Name, SSN, Sex, Address, Salary, Birth date, Department,
Supervisor, {Works on ( Project, Hours)}
WORKS_FOR
EMPLOYEE DEPARTMENT
1N
Name SSN . . .
Relationship instances of WORKS_FOR:
{(KV, CS), (Pan, EE), . . .}
ER Diagram for COMPANY
Database[2]
11
Relationship Type
 A relationship type R among n entity types E1,…,En is
a set of relationship instances ri, where each ri
associates n entities (e1,…,en), s.t. each ej Î Ej.
Informally, a relationship instance is an association of
entities, with exactly one entity from each
participating entity type.
12
Relationship Type
 The degree n of a relationship type is the number of
participating entity types.
 In the ER model relationships are explicitly
represented.
13
Entity Roles
 Each entity type in a relationship type plays a
particular role that is described by a role name. Role
names are especially important in recursive
relationship types where the same entity participates
in more than one role:
14
Employee
Supervision
Supervisor 1 N Supervisee
Weak Entity Type
 A weak entity type is one without any key attributes
of its own. Entities belonging to a weak entity type
are identified by being related to another entity type
( called identifying owner) through a relationship type
( called identifying relationship), in combination with
values of a set of its own attributes (called partial
key). A weak entity type has total participation
constraint w.r.t. its identifying relationship.
15
Relationship Attributes
 Relationship types can have attributes as well. in
case of 1:1 or 1:N relationships, attributes can be
migrated to one of the participating entity types.
16
Relationship[3]
17
Relationship[4]
18
Relationship[5]
19
Structural Constraints
 Structural constraints of a relationship type:
 Cardinality ratio: Limits the number of
relationship instances an entity can participate in,
eg. 1:1, 1:N, M:N
 Participation constraint: If each entity of an
entity type is required to participate in some
instance of a relationship type, then that
participation is total; otherwise, it is partial.
20
Structural Constraint Min, Max
 A more complete specification of the structural
constraint on a relationship type can be given by the
integer pair (min, max), which means an entity must
participate in at least min and at most max
relationship instances.
21
A ternary relationship generally represents more
information than 3 binary relationships[6]
22
A Weak Entity with a Terary Identifying
Relationship[7]
23
Introduction
 Database – collection of persistent data
 Database Management System (DBMS) – software
system that supports creation, population, and
querying of a database
Relational Database
Relational Database Management System (RDBMS)
Consists of a number of tables and single schema
(definition of tables and attributes)
Students (Sid, name, login, age, gpa)
 Students identifies the table
 Sid, name, login, age, gpa identify attributes
 Sid is primary key
An Example Table
• Students (Sid: string, name: string, login: string, age:
integer, gpa: real)
sid name login age gpa
50000 Dave dave@cs 19 3.3
53666 Jones jones@cs 18 3.4
53688 Smith smith@ee 18 3.2
53650 Smith smith@math 19 3.8
53831 Madayan madayan@music 11 1.8
53832 Guldu guldu@music 12 2.0
Another example: Courses
• Courses (cid, instructor, quarter, dept)
cid instructor quarter dept
Carnatic101 Jane Fall 06 Music
Reggae203 Bob Summer 06 Music
Topology101 Mary Spring 06 Math
History105 Alice Fall 06 History
Keys
Primary key – minimal subset of fields that is unique
identifier for a tuple
Sid is primary key for Students
cid is primary key for Courses
Foreign key –connections between tables
Courses (cid, instructor, quarter, dept)
Students (Sid, name, login, age, gpa)
How do we express which students take each course?
Many to many relationships
• In general, need a new table
Enrolled(cid, grade, studid)
Studid is foreign key that references Sid in Student
table
cid grade studid
Carnatic101 C 53831
Reggae203 B 53832
Topology112 A 53650
History 105 B 53666
sid name login
50000 Dave dave@cs
53666 Jones jones@cs
53688 Smith smith@ee
53650 Smith smith@math
53831 Madayan madayan@musi
53832 Guldu guldu@music
Enrolled
Student
Foreign
key
Relational Algebra
 Collection of operators for specifying queries
 Query describes step-by-step procedure for
computing answer (i.e., operational)
 Each operator accepts one or two relations as input
and returns a relation as output
 Relational algebra expression composed of multiple
operators
Basic operators
 Selection – return rows that meet some condition
 Projection – return column values
 Union
 Cross product
 Difference
 Other operators can be defined in terms of basic
operators
Example Schema (simplified)
 Courses (cid, instructor, quarter, dept)
 Students (Sid, name, gpa)
 Enrolled (cid, grade, studid)
Selection
Select students with gpa higher than 3.3 from S1:
σgpa>3.3(S1)
S1
sid name gpa
50000 Dave 3.3
53666 Jones 3.4
53688 Smith 3.2
53650 Smith 3.8
53831 Madayan 1.8
53832 Guldu 2.0
sid name gpa
53666 Jones 3.4
53650 Smith 3.8
Projection
Project name and gpa of all students in S1:
Πname, gpa(S1)
S1
Sid name gpa
50000 Dave 3.3
53666 Jones 3.4
53688 Smith 3.2
53650 Smith 3.8
53831 Madayan 1.8
53832 Guldu 2.0
name gpa
Dave 3.3
Jones 3.4
Smith 3.2
Smith 3.8
Madayan 1.8
Guldu 2.0
Combine Selection and Projection
 Project name and gpa of students in S1 with gpa
higher than 3.3:
 Πname,gpa(σgpa>3.3(S1))
Sid name gpa
50000 Dave 3.3
53666 Jones 3.4
53688 Smith 3.2
53650 Smith 3.8
53831 Madayan 1.8
53832 Guldu 2.0
name gpa
Jones 3.4
Smith 3.8
Set Operations
Union (R U S)
All tuples in R or S (or both)
R and S must have same number of fields
Corresponding fields must have same domains
Intersection (R ∩ S)
All tuples in both R and S
Set difference (R – S)
Tuples in R and not S
Set Operations
Cross product or Cartesian product (R x S)
All fields in R followed by all fields in S
One tuple (r,s) for each pair of tuples r ∈ R, s ∈ S
Example: Intersection
sid name gpa
50000 Dave 3.3
53666 Jones 3.4
53688 Smith 3.2
53650 Smith 3.8
53831 Madayan 1.8
53832 Guldu 2.0
sid name gpa
53666 Jones 3.4
53688 Smith 3.2
53700 Tom 3.5
53777 Jerry 2.8
53832 Guldu 2.0
S1 S2
S1 ∩ S2 =
sid name gpa
53666 Jones 3.4
53688 Smith 3.2
53832 Guldu 2.0
Joins
 Combine information from two or more tables
 Example: students enrolled in courses:
 S1 S1.sid=E.studidE
Sid name gpa
50000 Dave 3.3
53666 Jones 3.4
53688 Smith 3.2
53650 Smith 3.8
53831 Madayan 1.8
53832 Guldu 2.0
cid grade studid
Carnatic101 C 53831
Reggae203 B 53832
Topology112 A 53650
History 105 B 53666
S1
E
Joins
sid name gpa cid grade studid
53666 Jones 3.4 History105 B 53666
53650 Smith 3.8 Topology112 A 53650
53831 Madayan 1.8 Carnatic101 C 53831
53832 Guldu 2.0 Reggae203 B 53832
Sid name gpa
50000 Dave 3.3
53666 Jones 3.4
53688 Smith 3.2
53650 Smith 3.8
53831 Madayan 1.8
53832 Guldu 2.0
cid grade studid
Carnatic101 C 53831
Reggae203 B 53832
Topology112 A 53650
History 105 B 53666
S1
E
Relational Algebra Summary
 Algebras are useful to manipulate data types (relations in
this case)
 Set-oriented
 Brings some clarity to what needs to be done
 Opportunities for optimization
 May have different expressions that do same thing
 We will see examples of algebras for other types of data
in this course
Intro to SQL
CREATE TABLE
Create a new table, e.g., students, courses, enrolled
SELECT-FROM-WHERE
List all CS courses
INSERT
Add a new student, course, or enroll a student in a
course
Create Table
CREATE TABLE Enrolled
(studid CHAR(20),
cid CHAR(20),
grade CHAR(20),
PRIMARY KEY (studid, cid),
FOREIGN KEY (studid) references Students)
Select-From-Where query
“Find all students who are under 18”
SELECT *
FROM Students S
WHERE S.age < 18
Queries across multiple tables
(joins)
“Print the student name and course ID where the
student received an ‘A’ in the course”
SELECT S.name, E.cid
FROM Students S, Enrolled E
WHERE S.sid = E.studid AND E.grade = ‘A’
Other SQL features
 MIN, MAX, AVG
 Find highest grade in fall database course
 COUNT, DISTINCT
 How many students enrolled in CS courses in the
fall?
 ORDER BY, GROUP BY
 Rank students by their grade in fall database
course
Views
 Virtual table defined on base tables defined by a query
 Single or multiple tables
 Security – “hide” certain attributes from users
 Show students in each course but hide their grades
 Ease of use – expression that is more intuitively
obvious to user
 Views can be materialized to improve query
performance
Views
• Suppose we often need names of students who got a
‘B’ in some course:
CREATE VIEW B_Students(name, sid, course)
AS SELECT S.sname, S.sid, E.cid
FROM Students S, Enrolled E
WHERE S.sid=E.studid and E.grade = ‘B’
Name Sid course
Jones 53666 History105
Guldu 53832 Reggae203
Indexes
 Idea: speed up access to desired data
 “Find all students with gpa > 3.3
 May need to scan entire table
 Index consists of a set of entries pointing to locations
of each search key
Types of Indexes
 Clustered vs. Unclustered
 Clustered- ordering of data records same as
ordering of data entries in the index
 Unclustered- data records in different order from
index
 Primary vs. Secondary
 Primary – index on fields that include primary key
 Secondary – other indexes
Example: Clustered Index
 Sorted by sid
sid name gpa
50000 Dave 3.3
53650 Smith 3.8
53666 Jones 3.4
53688 Smith 3.2
53831 Madayan 1.8
53832 Guldu 2.0
50000
53600
53800
Example: Unclustered Index
 Sorted by sid
 Index on gpa
sid name gpa
50000 Dave 3.3
53650 Smith 3.8
53666 Jones 3.4
53688 Smith 3.2
53831 Madayan 1.8
53832 Guldu 2.0
1.8
2.0
3.2
3.3
3.4
3.8
Comments on Indexes
 Indexes can significantly speed up query execution
 But inserts more costly
 May have high storage overhead
 Need to choose attributes to index wisely!
 What queries are run most frequently?
 What queries could benefit most from an index?
 Preview of things to come: SDSS
Summary: Why are RDBMS
useful?
 Data independence – provides abstract view of the
data, without details of storage
 Efficient data access – uses techniques to store and
retrieve data efficiently
 Reduced application development time – many
important functions already supported
 Centralized data administration
 Data Integrity and Security
 Concurrency control and recovery
So, why don’t scientists use them?
 “I tried to use databases in my project, but they were
just too [slow | hard-to-use | expensive | complex] . So
I use files”.
 Gray and Szalay, Where Rubber Meets the Sky:
Bridging the Gap Between Databases and Science
Some other limitations of
RDBMS
 Arrays
 Hierarchical data
Example: Taxonomy of
Organisms[8] Hierarchy of categories:
 Kingdom - phylum – class – order – family – genus – species
 How would you design a relational schema for this?
Animals
Chordates
Vertebrates
Arthropods
birds
insects spiders crustaceans
reptiles mammals
References
1. http://en.wikipedia.org/wiki/Entity
%E2%80%93relationship_model
2. http://simple.wikipedia.org/wiki/Entity-relationship_model
3. https://cs.uwaterloo.ca/~david/cs338/10%20ER%20Model.pdf
4. http://people.cs.pitt.edu/~chang/156/03ERmodel.html
5. http://www.aquafold.com/aquadatastudio/er_modeler.html
6. http://searchdatamanagement.techtarget.com/guide/Limitations-of-
entity-relationship-models-in-data-modeling
7. Database System Concepts: Abraham Silberschatz, Henry F. Korth
& S., Sudarshan, TATA Mcgraw Hill.
8. Database Systems Concepts, design and Applications 2/e, Singh S.
K, PearsonEducation
9. SQL- PL/SQL, Ivan bayross, BPB Publications. 58
Images References
1. 1.http://www.tutorialspoint.com/dbms/er_model_basic_concepts.ht
m
2. 2.http://www.tutorialspoint.com/dbms/er_diagram_representation.h
tm
3. https://www.google.co.in/search?
q=ER+Diagram+for+COMPANY+Database+images+in+database
+management+system&biw=1024&bih=643&tbm=isch&tbo=u&s
ource=univ&sa=X&ei=2a-
qVImcMciJuATmvYLYCQ&ved=0CBsQsAQ
Chapter 3 59

Mais conteúdo relacionado

Mais procurados

4 the relational data model and relational database constraints
4 the relational data model and relational database constraints4 the relational data model and relational database constraints
4 the relational data model and relational database constraintsKumar
 
The Relational Data Model and Relational Database Constraints Ch5 (Navathe 4t...
The Relational Data Model and Relational Database Constraints Ch5 (Navathe 4t...The Relational Data Model and Relational Database Constraints Ch5 (Navathe 4t...
The Relational Data Model and Relational Database Constraints Ch5 (Navathe 4t...Raj vardhan
 
Dbms ii mca-ch4-relational model-2013
Dbms ii mca-ch4-relational model-2013Dbms ii mca-ch4-relational model-2013
Dbms ii mca-ch4-relational model-2013Prosanta Ghosh
 
Fundamentals of database system - Relational data model and relational datab...
Fundamentals of database system  - Relational data model and relational datab...Fundamentals of database system  - Relational data model and relational datab...
Fundamentals of database system - Relational data model and relational datab...Mustafa Kamel Mohammadi
 
CHAPTER 2 DBMS IN EASY WAY BY MILAN PATEL
CHAPTER 2 DBMS IN EASY WAY BY  MILAN PATELCHAPTER 2 DBMS IN EASY WAY BY  MILAN PATEL
CHAPTER 2 DBMS IN EASY WAY BY MILAN PATELShashi Patel
 
Chapter 2 Relational Data Model-part 2
Chapter 2 Relational Data Model-part 2Chapter 2 Relational Data Model-part 2
Chapter 2 Relational Data Model-part 2Eddyzulham Mahluzydde
 
Database Design and Normalization Techniques
Database Design and Normalization TechniquesDatabase Design and Normalization Techniques
Database Design and Normalization TechniquesNishant Munjal
 
Relational database intro for marketers
Relational database intro for marketersRelational database intro for marketers
Relational database intro for marketersSteve Finlay
 
Eer >r.model
Eer >r.modelEer >r.model
Eer >r.modellavya3
 
Basic database analysis(database)
Basic database analysis(database)Basic database analysis(database)
Basic database analysis(database)welcometofacebook
 
Cardinality and participation constraints
Cardinality and participation constraintsCardinality and participation constraints
Cardinality and participation constraintsNikhil Deswal
 
Relational Model - An Introduction
Relational Model - An IntroductionRelational Model - An Introduction
Relational Model - An IntroductionRajeev Srivastava
 

Mais procurados (20)

4 the relational data model and relational database constraints
4 the relational data model and relational database constraints4 the relational data model and relational database constraints
4 the relational data model and relational database constraints
 
The Relational Data Model and Relational Database Constraints Ch5 (Navathe 4t...
The Relational Data Model and Relational Database Constraints Ch5 (Navathe 4t...The Relational Data Model and Relational Database Constraints Ch5 (Navathe 4t...
The Relational Data Model and Relational Database Constraints Ch5 (Navathe 4t...
 
Dbms ii mca-ch4-relational model-2013
Dbms ii mca-ch4-relational model-2013Dbms ii mca-ch4-relational model-2013
Dbms ii mca-ch4-relational model-2013
 
Fundamentals of database system - Relational data model and relational datab...
Fundamentals of database system  - Relational data model and relational datab...Fundamentals of database system  - Relational data model and relational datab...
Fundamentals of database system - Relational data model and relational datab...
 
CHAPTER 2 DBMS IN EASY WAY BY MILAN PATEL
CHAPTER 2 DBMS IN EASY WAY BY  MILAN PATELCHAPTER 2 DBMS IN EASY WAY BY  MILAN PATEL
CHAPTER 2 DBMS IN EASY WAY BY MILAN PATEL
 
Chapter 2 Relational Data Model-part 2
Chapter 2 Relational Data Model-part 2Chapter 2 Relational Data Model-part 2
Chapter 2 Relational Data Model-part 2
 
Relational model
Relational modelRelational model
Relational model
 
Database Design and Normalization Techniques
Database Design and Normalization TechniquesDatabase Design and Normalization Techniques
Database Design and Normalization Techniques
 
Lesson03 the relational model
Lesson03 the relational modelLesson03 the relational model
Lesson03 the relational model
 
Relational database intro for marketers
Relational database intro for marketersRelational database intro for marketers
Relational database intro for marketers
 
Eer >r.model
Eer >r.modelEer >r.model
Eer >r.model
 
ch6
ch6ch6
ch6
 
Relational model
Relational modelRelational model
Relational model
 
Basic database analysis(database)
Basic database analysis(database)Basic database analysis(database)
Basic database analysis(database)
 
Bc0041
Bc0041Bc0041
Bc0041
 
DBMS CS2
DBMS CS2DBMS CS2
DBMS CS2
 
Cardinality and participation constraints
Cardinality and participation constraintsCardinality and participation constraints
Cardinality and participation constraints
 
Er Modeling
Er ModelingEr Modeling
Er Modeling
 
Relational Model - An Introduction
Relational Model - An IntroductionRelational Model - An Introduction
Relational Model - An Introduction
 
DBMS CS 4-5
DBMS CS 4-5DBMS CS 4-5
DBMS CS 4-5
 

Destaque

SMART International Symposium for Next Generation Infrastructure: Bio-inspire...
SMART International Symposium for Next Generation Infrastructure: Bio-inspire...SMART International Symposium for Next Generation Infrastructure: Bio-inspire...
SMART International Symposium for Next Generation Infrastructure: Bio-inspire...SMART Infrastructure Facility
 
Desigining of Database - ER Model
Desigining of Database - ER ModelDesigining of Database - ER Model
Desigining of Database - ER ModelAjay Chhimpa
 
Cloude computing By Gayatri Kumbhalkar
Cloude computing By Gayatri KumbhalkarCloude computing By Gayatri Kumbhalkar
Cloude computing By Gayatri KumbhalkarBhushan Kumbhalkar
 
Bio-inspired Artificial Intelligence for Collective Systems
Bio-inspired Artificial Intelligence for Collective SystemsBio-inspired Artificial Intelligence for Collective Systems
Bio-inspired Artificial Intelligence for Collective SystemsAchini_Adikari
 
My seminar on bluejacking
My seminar on bluejackingMy seminar on bluejacking
My seminar on bluejackingAkshita Pillai
 
Google Cloud Monitoring
Google Cloud MonitoringGoogle Cloud Monitoring
Google Cloud MonitoringSimon Su
 
Artificial Neural Network
Artificial Neural NetworkArtificial Neural Network
Artificial Neural NetworkManasa Mona
 
Content based image retrieval(cbir)
Content based image retrieval(cbir)Content based image retrieval(cbir)
Content based image retrieval(cbir)paddu123
 
JCConf 2016 - Google Dataflow 小試
JCConf 2016 - Google Dataflow 小試JCConf 2016 - Google Dataflow 小試
JCConf 2016 - Google Dataflow 小試Simon Su
 
Er diagram practical examples
Er diagram practical examplesEr diagram practical examples
Er diagram practical examplesRahul Khanwani
 
Library management
Library managementLibrary management
Library managementfarouq umar
 
library management system in SQL
library management system in SQLlibrary management system in SQL
library management system in SQLfarouq umar
 
Disaster Recovery & Data Backup Strategies
Disaster Recovery & Data Backup StrategiesDisaster Recovery & Data Backup Strategies
Disaster Recovery & Data Backup StrategiesSpiceworks
 
Entity Relationship Diagram presentation
Entity Relationship Diagram presentationEntity Relationship Diagram presentation
Entity Relationship Diagram presentationSopov Chan
 

Destaque (20)

About Veritiv
About VeritivAbout Veritiv
About Veritiv
 
SMART International Symposium for Next Generation Infrastructure: Bio-inspire...
SMART International Symposium for Next Generation Infrastructure: Bio-inspire...SMART International Symposium for Next Generation Infrastructure: Bio-inspire...
SMART International Symposium for Next Generation Infrastructure: Bio-inspire...
 
Desigining of Database - ER Model
Desigining of Database - ER ModelDesigining of Database - ER Model
Desigining of Database - ER Model
 
Cloude computing By Gayatri Kumbhalkar
Cloude computing By Gayatri KumbhalkarCloude computing By Gayatri Kumbhalkar
Cloude computing By Gayatri Kumbhalkar
 
Bio-inspired Artificial Intelligence for Collective Systems
Bio-inspired Artificial Intelligence for Collective SystemsBio-inspired Artificial Intelligence for Collective Systems
Bio-inspired Artificial Intelligence for Collective Systems
 
My seminar on bluejacking
My seminar on bluejackingMy seminar on bluejacking
My seminar on bluejacking
 
cloude computing
cloude computingcloude computing
cloude computing
 
Google Cloud Monitoring
Google Cloud MonitoringGoogle Cloud Monitoring
Google Cloud Monitoring
 
Artificial Neural Network
Artificial Neural NetworkArtificial Neural Network
Artificial Neural Network
 
Content based image retrieval(cbir)
Content based image retrieval(cbir)Content based image retrieval(cbir)
Content based image retrieval(cbir)
 
JCConf 2016 - Google Dataflow 小試
JCConf 2016 - Google Dataflow 小試JCConf 2016 - Google Dataflow 小試
JCConf 2016 - Google Dataflow 小試
 
Zenoss seminar
Zenoss seminarZenoss seminar
Zenoss seminar
 
Er diagram practical examples
Er diagram practical examplesEr diagram practical examples
Er diagram practical examples
 
Bluejacking
BluejackingBluejacking
Bluejacking
 
Chapter2
Chapter2Chapter2
Chapter2
 
Library management
Library managementLibrary management
Library management
 
library management system in SQL
library management system in SQLlibrary management system in SQL
library management system in SQL
 
Disaster Recovery & Data Backup Strategies
Disaster Recovery & Data Backup StrategiesDisaster Recovery & Data Backup Strategies
Disaster Recovery & Data Backup Strategies
 
Entity Relationship Diagram presentation
Entity Relationship Diagram presentationEntity Relationship Diagram presentation
Entity Relationship Diagram presentation
 
Pattern Recognition
Pattern RecognitionPattern Recognition
Pattern Recognition
 

Semelhante a Mca ii-dbms- u-iii-sql concepts

Bsc cs ii-dbms- u-iii-data modeling using e.r. model (entity relationship model)
Bsc cs ii-dbms- u-iii-data modeling using e.r. model (entity relationship model)Bsc cs ii-dbms- u-iii-data modeling using e.r. model (entity relationship model)
Bsc cs ii-dbms- u-iii-data modeling using e.r. model (entity relationship model)Rai University
 
Dbms ii mca-ch3-er-model-2013
Dbms ii mca-ch3-er-model-2013Dbms ii mca-ch3-er-model-2013
Dbms ii mca-ch3-er-model-2013Prosanta Ghosh
 
2. relational model_150903
2. relational model_1509032. relational model_150903
2. relational model_150903Dika Handika
 
relational model.pptx
relational model.pptxrelational model.pptx
relational model.pptxThangamaniR3
 
03 Ch3 Notes Revised
03 Ch3 Notes Revised03 Ch3 Notes Revised
03 Ch3 Notes Revisedguest6f408c
 
Database Management System
Database Management System Database Management System
Database Management System FellowBuddy.com
 
relationsandfunctionslessonproper-160929053921.pdf
relationsandfunctionslessonproper-160929053921.pdfrelationsandfunctionslessonproper-160929053921.pdf
relationsandfunctionslessonproper-160929053921.pdfBhanuCharan9
 

Semelhante a Mca ii-dbms- u-iii-sql concepts (20)

Bsc cs ii-dbms- u-iii-data modeling using e.r. model (entity relationship model)
Bsc cs ii-dbms- u-iii-data modeling using e.r. model (entity relationship model)Bsc cs ii-dbms- u-iii-data modeling using e.r. model (entity relationship model)
Bsc cs ii-dbms- u-iii-data modeling using e.r. model (entity relationship model)
 
Ra Revision
Ra RevisionRa Revision
Ra Revision
 
Relational+algebra (1)
Relational+algebra (1)Relational+algebra (1)
Relational+algebra (1)
 
Unit03 dbms
Unit03 dbmsUnit03 dbms
Unit03 dbms
 
Unit03 dbms
Unit03 dbmsUnit03 dbms
Unit03 dbms
 
RDBMS
RDBMSRDBMS
RDBMS
 
DBMS Unit-2.pdf
DBMS Unit-2.pdfDBMS Unit-2.pdf
DBMS Unit-2.pdf
 
Rdbms (2)
Rdbms (2)Rdbms (2)
Rdbms (2)
 
Dbms ii mca-ch3-er-model-2013
Dbms ii mca-ch3-er-model-2013Dbms ii mca-ch3-er-model-2013
Dbms ii mca-ch3-er-model-2013
 
Sq lite module3
Sq lite module3Sq lite module3
Sq lite module3
 
Dbms relational model
Dbms relational modelDbms relational model
Dbms relational model
 
2. relational model_150903
2. relational model_1509032. relational model_150903
2. relational model_150903
 
Db lec 02_new
Db lec 02_newDb lec 02_new
Db lec 02_new
 
Unit-2.pdf
Unit-2.pdfUnit-2.pdf
Unit-2.pdf
 
relational model.pptx
relational model.pptxrelational model.pptx
relational model.pptx
 
ERmodel (2).pdf
ERmodel (2).pdfERmodel (2).pdf
ERmodel (2).pdf
 
03 Ch3 Notes Revised
03 Ch3 Notes Revised03 Ch3 Notes Revised
03 Ch3 Notes Revised
 
3_Relational_Model.pdf
3_Relational_Model.pdf3_Relational_Model.pdf
3_Relational_Model.pdf
 
Database Management System
Database Management System Database Management System
Database Management System
 
relationsandfunctionslessonproper-160929053921.pdf
relationsandfunctionslessonproper-160929053921.pdfrelationsandfunctionslessonproper-160929053921.pdf
relationsandfunctionslessonproper-160929053921.pdf
 

Mais de Rai University

Brochure Rai University
Brochure Rai University Brochure Rai University
Brochure Rai University Rai University
 
Bdft ii, tmt, unit-iii, dyeing & types of dyeing,
Bdft ii, tmt, unit-iii,  dyeing & types of dyeing,Bdft ii, tmt, unit-iii,  dyeing & types of dyeing,
Bdft ii, tmt, unit-iii, dyeing & types of dyeing,Rai University
 
Bsc agri 2 pae u-4.4 publicrevenue-presentation-130208082149-phpapp02
Bsc agri  2 pae  u-4.4 publicrevenue-presentation-130208082149-phpapp02Bsc agri  2 pae  u-4.4 publicrevenue-presentation-130208082149-phpapp02
Bsc agri 2 pae u-4.4 publicrevenue-presentation-130208082149-phpapp02Rai University
 
Bsc agri 2 pae u-4.3 public expenditure
Bsc agri  2 pae  u-4.3 public expenditureBsc agri  2 pae  u-4.3 public expenditure
Bsc agri 2 pae u-4.3 public expenditureRai University
 
Bsc agri 2 pae u-4.2 public finance
Bsc agri  2 pae  u-4.2 public financeBsc agri  2 pae  u-4.2 public finance
Bsc agri 2 pae u-4.2 public financeRai University
 
Bsc agri 2 pae u-4.1 introduction
Bsc agri  2 pae  u-4.1 introductionBsc agri  2 pae  u-4.1 introduction
Bsc agri 2 pae u-4.1 introductionRai University
 
Bsc agri 2 pae u-3.3 inflation
Bsc agri  2 pae  u-3.3  inflationBsc agri  2 pae  u-3.3  inflation
Bsc agri 2 pae u-3.3 inflationRai University
 
Bsc agri 2 pae u-3.2 introduction to macro economics
Bsc agri  2 pae  u-3.2 introduction to macro economicsBsc agri  2 pae  u-3.2 introduction to macro economics
Bsc agri 2 pae u-3.2 introduction to macro economicsRai University
 
Bsc agri 2 pae u-3.1 marketstructure
Bsc agri  2 pae  u-3.1 marketstructureBsc agri  2 pae  u-3.1 marketstructure
Bsc agri 2 pae u-3.1 marketstructureRai University
 
Bsc agri 2 pae u-3 perfect-competition
Bsc agri  2 pae  u-3 perfect-competitionBsc agri  2 pae  u-3 perfect-competition
Bsc agri 2 pae u-3 perfect-competitionRai University
 

Mais de Rai University (20)

Brochure Rai University
Brochure Rai University Brochure Rai University
Brochure Rai University
 
Mm unit 4point2
Mm unit 4point2Mm unit 4point2
Mm unit 4point2
 
Mm unit 4point1
Mm unit 4point1Mm unit 4point1
Mm unit 4point1
 
Mm unit 4point3
Mm unit 4point3Mm unit 4point3
Mm unit 4point3
 
Mm unit 3point2
Mm unit 3point2Mm unit 3point2
Mm unit 3point2
 
Mm unit 3point1
Mm unit 3point1Mm unit 3point1
Mm unit 3point1
 
Mm unit 2point2
Mm unit 2point2Mm unit 2point2
Mm unit 2point2
 
Mm unit 2 point 1
Mm unit 2 point 1Mm unit 2 point 1
Mm unit 2 point 1
 
Mm unit 1point3
Mm unit 1point3Mm unit 1point3
Mm unit 1point3
 
Mm unit 1point2
Mm unit 1point2Mm unit 1point2
Mm unit 1point2
 
Mm unit 1point1
Mm unit 1point1Mm unit 1point1
Mm unit 1point1
 
Bdft ii, tmt, unit-iii, dyeing & types of dyeing,
Bdft ii, tmt, unit-iii,  dyeing & types of dyeing,Bdft ii, tmt, unit-iii,  dyeing & types of dyeing,
Bdft ii, tmt, unit-iii, dyeing & types of dyeing,
 
Bsc agri 2 pae u-4.4 publicrevenue-presentation-130208082149-phpapp02
Bsc agri  2 pae  u-4.4 publicrevenue-presentation-130208082149-phpapp02Bsc agri  2 pae  u-4.4 publicrevenue-presentation-130208082149-phpapp02
Bsc agri 2 pae u-4.4 publicrevenue-presentation-130208082149-phpapp02
 
Bsc agri 2 pae u-4.3 public expenditure
Bsc agri  2 pae  u-4.3 public expenditureBsc agri  2 pae  u-4.3 public expenditure
Bsc agri 2 pae u-4.3 public expenditure
 
Bsc agri 2 pae u-4.2 public finance
Bsc agri  2 pae  u-4.2 public financeBsc agri  2 pae  u-4.2 public finance
Bsc agri 2 pae u-4.2 public finance
 
Bsc agri 2 pae u-4.1 introduction
Bsc agri  2 pae  u-4.1 introductionBsc agri  2 pae  u-4.1 introduction
Bsc agri 2 pae u-4.1 introduction
 
Bsc agri 2 pae u-3.3 inflation
Bsc agri  2 pae  u-3.3  inflationBsc agri  2 pae  u-3.3  inflation
Bsc agri 2 pae u-3.3 inflation
 
Bsc agri 2 pae u-3.2 introduction to macro economics
Bsc agri  2 pae  u-3.2 introduction to macro economicsBsc agri  2 pae  u-3.2 introduction to macro economics
Bsc agri 2 pae u-3.2 introduction to macro economics
 
Bsc agri 2 pae u-3.1 marketstructure
Bsc agri  2 pae  u-3.1 marketstructureBsc agri  2 pae  u-3.1 marketstructure
Bsc agri 2 pae u-3.1 marketstructure
 
Bsc agri 2 pae u-3 perfect-competition
Bsc agri  2 pae  u-3 perfect-competitionBsc agri  2 pae  u-3 perfect-competition
Bsc agri 2 pae u-3 perfect-competition
 

Último

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
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
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
 
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
 
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
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
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
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
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
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIShubhangi Sonawane
 
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
 

Último (20)

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
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
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
 
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
 
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
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.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
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
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
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
 
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
 

Mca ii-dbms- u-iii-sql concepts

  • 2. Entity-Relationship(ER) Model  The ER model is a high-level conceptual data model. It has not been implemented in any commercial DBMS (?), but is a powerful short hand often used in database design for a first rendition of the miniworld.  The ER model was introduced by Peter Chen in 1976, and is now the most widely used conceptual data model. 2
  • 4. Definitions  An entity is an object in the miniworld.  An attribute of an entity can have a value from a value set (domain)  Each entity belongs to some one entity type s.t. entities in one entity type have the same attributes (so each entity type is a set of similar entities). 4
  • 5. Definitions  A key attribute of an entity type is one whose value uniquely identifies an entity of that type.  A combination of attributes may form a composite key.  If there is no applicable value for an attribute that attribute is set to a null value. 5
  • 6. 6 Entity Type / Entity Set Entity Type (Intension): EMPLOYEE Attributes: Name, Age, Salary Entity Set (Extension): e1 = (John Smith, 55, 80000) e2 = (Joe Doe, 40, 20000) e3 = (Jane Doe, 27, 30000) . . .
  • 7. Attributes  Attributes can be  composite / simple (atomic)  single-valued / multivalued  stored / derived  key / nonkey. 7
  • 8. Attribute Examples 8 Name = John Doe Birth date = May 10, 1989 Age = 9 Degree = null SSN = 123456789 Name = John Doe Birth date = May 10 Birth year = 1989 Age = 9 Degree = null SSN = 123456789 Name = Jane Doe Birthrate = July 11, 1960 Age = 38 Degree = B.S., M.S. SSN = 987654321
  • 10. 10 EMPLOYEE Name, SSN, Sex, Address, Salary, Birth date, Department, Supervisor, {Works on ( Project, Hours)} WORKS_FOR EMPLOYEE DEPARTMENT 1N Name SSN . . . Relationship instances of WORKS_FOR: {(KV, CS), (Pan, EE), . . .}
  • 11. ER Diagram for COMPANY Database[2] 11
  • 12. Relationship Type  A relationship type R among n entity types E1,…,En is a set of relationship instances ri, where each ri associates n entities (e1,…,en), s.t. each ej Î Ej. Informally, a relationship instance is an association of entities, with exactly one entity from each participating entity type. 12
  • 13. Relationship Type  The degree n of a relationship type is the number of participating entity types.  In the ER model relationships are explicitly represented. 13
  • 14. Entity Roles  Each entity type in a relationship type plays a particular role that is described by a role name. Role names are especially important in recursive relationship types where the same entity participates in more than one role: 14 Employee Supervision Supervisor 1 N Supervisee
  • 15. Weak Entity Type  A weak entity type is one without any key attributes of its own. Entities belonging to a weak entity type are identified by being related to another entity type ( called identifying owner) through a relationship type ( called identifying relationship), in combination with values of a set of its own attributes (called partial key). A weak entity type has total participation constraint w.r.t. its identifying relationship. 15
  • 16. Relationship Attributes  Relationship types can have attributes as well. in case of 1:1 or 1:N relationships, attributes can be migrated to one of the participating entity types. 16
  • 20. Structural Constraints  Structural constraints of a relationship type:  Cardinality ratio: Limits the number of relationship instances an entity can participate in, eg. 1:1, 1:N, M:N  Participation constraint: If each entity of an entity type is required to participate in some instance of a relationship type, then that participation is total; otherwise, it is partial. 20
  • 21. Structural Constraint Min, Max  A more complete specification of the structural constraint on a relationship type can be given by the integer pair (min, max), which means an entity must participate in at least min and at most max relationship instances. 21
  • 22. A ternary relationship generally represents more information than 3 binary relationships[6] 22
  • 23. A Weak Entity with a Terary Identifying Relationship[7] 23
  • 24. Introduction  Database – collection of persistent data  Database Management System (DBMS) – software system that supports creation, population, and querying of a database
  • 25. Relational Database Relational Database Management System (RDBMS) Consists of a number of tables and single schema (definition of tables and attributes) Students (Sid, name, login, age, gpa)  Students identifies the table  Sid, name, login, age, gpa identify attributes  Sid is primary key
  • 26. An Example Table • Students (Sid: string, name: string, login: string, age: integer, gpa: real) sid name login age gpa 50000 Dave dave@cs 19 3.3 53666 Jones jones@cs 18 3.4 53688 Smith smith@ee 18 3.2 53650 Smith smith@math 19 3.8 53831 Madayan madayan@music 11 1.8 53832 Guldu guldu@music 12 2.0
  • 27. Another example: Courses • Courses (cid, instructor, quarter, dept) cid instructor quarter dept Carnatic101 Jane Fall 06 Music Reggae203 Bob Summer 06 Music Topology101 Mary Spring 06 Math History105 Alice Fall 06 History
  • 28. Keys Primary key – minimal subset of fields that is unique identifier for a tuple Sid is primary key for Students cid is primary key for Courses Foreign key –connections between tables Courses (cid, instructor, quarter, dept) Students (Sid, name, login, age, gpa) How do we express which students take each course?
  • 29. Many to many relationships • In general, need a new table Enrolled(cid, grade, studid) Studid is foreign key that references Sid in Student table cid grade studid Carnatic101 C 53831 Reggae203 B 53832 Topology112 A 53650 History 105 B 53666 sid name login 50000 Dave dave@cs 53666 Jones jones@cs 53688 Smith smith@ee 53650 Smith smith@math 53831 Madayan madayan@musi 53832 Guldu guldu@music Enrolled Student Foreign key
  • 30. Relational Algebra  Collection of operators for specifying queries  Query describes step-by-step procedure for computing answer (i.e., operational)  Each operator accepts one or two relations as input and returns a relation as output  Relational algebra expression composed of multiple operators
  • 31. Basic operators  Selection – return rows that meet some condition  Projection – return column values  Union  Cross product  Difference  Other operators can be defined in terms of basic operators
  • 32. Example Schema (simplified)  Courses (cid, instructor, quarter, dept)  Students (Sid, name, gpa)  Enrolled (cid, grade, studid)
  • 33. Selection Select students with gpa higher than 3.3 from S1: σgpa>3.3(S1) S1 sid name gpa 50000 Dave 3.3 53666 Jones 3.4 53688 Smith 3.2 53650 Smith 3.8 53831 Madayan 1.8 53832 Guldu 2.0 sid name gpa 53666 Jones 3.4 53650 Smith 3.8
  • 34. Projection Project name and gpa of all students in S1: Πname, gpa(S1) S1 Sid name gpa 50000 Dave 3.3 53666 Jones 3.4 53688 Smith 3.2 53650 Smith 3.8 53831 Madayan 1.8 53832 Guldu 2.0 name gpa Dave 3.3 Jones 3.4 Smith 3.2 Smith 3.8 Madayan 1.8 Guldu 2.0
  • 35. Combine Selection and Projection  Project name and gpa of students in S1 with gpa higher than 3.3:  Πname,gpa(σgpa>3.3(S1)) Sid name gpa 50000 Dave 3.3 53666 Jones 3.4 53688 Smith 3.2 53650 Smith 3.8 53831 Madayan 1.8 53832 Guldu 2.0 name gpa Jones 3.4 Smith 3.8
  • 36. Set Operations Union (R U S) All tuples in R or S (or both) R and S must have same number of fields Corresponding fields must have same domains Intersection (R ∩ S) All tuples in both R and S Set difference (R – S) Tuples in R and not S
  • 37. Set Operations Cross product or Cartesian product (R x S) All fields in R followed by all fields in S One tuple (r,s) for each pair of tuples r ∈ R, s ∈ S
  • 38. Example: Intersection sid name gpa 50000 Dave 3.3 53666 Jones 3.4 53688 Smith 3.2 53650 Smith 3.8 53831 Madayan 1.8 53832 Guldu 2.0 sid name gpa 53666 Jones 3.4 53688 Smith 3.2 53700 Tom 3.5 53777 Jerry 2.8 53832 Guldu 2.0 S1 S2 S1 ∩ S2 = sid name gpa 53666 Jones 3.4 53688 Smith 3.2 53832 Guldu 2.0
  • 39. Joins  Combine information from two or more tables  Example: students enrolled in courses:  S1 S1.sid=E.studidE Sid name gpa 50000 Dave 3.3 53666 Jones 3.4 53688 Smith 3.2 53650 Smith 3.8 53831 Madayan 1.8 53832 Guldu 2.0 cid grade studid Carnatic101 C 53831 Reggae203 B 53832 Topology112 A 53650 History 105 B 53666 S1 E
  • 40. Joins sid name gpa cid grade studid 53666 Jones 3.4 History105 B 53666 53650 Smith 3.8 Topology112 A 53650 53831 Madayan 1.8 Carnatic101 C 53831 53832 Guldu 2.0 Reggae203 B 53832 Sid name gpa 50000 Dave 3.3 53666 Jones 3.4 53688 Smith 3.2 53650 Smith 3.8 53831 Madayan 1.8 53832 Guldu 2.0 cid grade studid Carnatic101 C 53831 Reggae203 B 53832 Topology112 A 53650 History 105 B 53666 S1 E
  • 41. Relational Algebra Summary  Algebras are useful to manipulate data types (relations in this case)  Set-oriented  Brings some clarity to what needs to be done  Opportunities for optimization  May have different expressions that do same thing  We will see examples of algebras for other types of data in this course
  • 42. Intro to SQL CREATE TABLE Create a new table, e.g., students, courses, enrolled SELECT-FROM-WHERE List all CS courses INSERT Add a new student, course, or enroll a student in a course
  • 43. Create Table CREATE TABLE Enrolled (studid CHAR(20), cid CHAR(20), grade CHAR(20), PRIMARY KEY (studid, cid), FOREIGN KEY (studid) references Students)
  • 44. Select-From-Where query “Find all students who are under 18” SELECT * FROM Students S WHERE S.age < 18
  • 45. Queries across multiple tables (joins) “Print the student name and course ID where the student received an ‘A’ in the course” SELECT S.name, E.cid FROM Students S, Enrolled E WHERE S.sid = E.studid AND E.grade = ‘A’
  • 46. Other SQL features  MIN, MAX, AVG  Find highest grade in fall database course  COUNT, DISTINCT  How many students enrolled in CS courses in the fall?  ORDER BY, GROUP BY  Rank students by their grade in fall database course
  • 47. Views  Virtual table defined on base tables defined by a query  Single or multiple tables  Security – “hide” certain attributes from users  Show students in each course but hide their grades  Ease of use – expression that is more intuitively obvious to user  Views can be materialized to improve query performance
  • 48. Views • Suppose we often need names of students who got a ‘B’ in some course: CREATE VIEW B_Students(name, sid, course) AS SELECT S.sname, S.sid, E.cid FROM Students S, Enrolled E WHERE S.sid=E.studid and E.grade = ‘B’ Name Sid course Jones 53666 History105 Guldu 53832 Reggae203
  • 49. Indexes  Idea: speed up access to desired data  “Find all students with gpa > 3.3  May need to scan entire table  Index consists of a set of entries pointing to locations of each search key
  • 50. Types of Indexes  Clustered vs. Unclustered  Clustered- ordering of data records same as ordering of data entries in the index  Unclustered- data records in different order from index  Primary vs. Secondary  Primary – index on fields that include primary key  Secondary – other indexes
  • 51. Example: Clustered Index  Sorted by sid sid name gpa 50000 Dave 3.3 53650 Smith 3.8 53666 Jones 3.4 53688 Smith 3.2 53831 Madayan 1.8 53832 Guldu 2.0 50000 53600 53800
  • 52. Example: Unclustered Index  Sorted by sid  Index on gpa sid name gpa 50000 Dave 3.3 53650 Smith 3.8 53666 Jones 3.4 53688 Smith 3.2 53831 Madayan 1.8 53832 Guldu 2.0 1.8 2.0 3.2 3.3 3.4 3.8
  • 53. Comments on Indexes  Indexes can significantly speed up query execution  But inserts more costly  May have high storage overhead  Need to choose attributes to index wisely!  What queries are run most frequently?  What queries could benefit most from an index?  Preview of things to come: SDSS
  • 54. Summary: Why are RDBMS useful?  Data independence – provides abstract view of the data, without details of storage  Efficient data access – uses techniques to store and retrieve data efficiently  Reduced application development time – many important functions already supported  Centralized data administration  Data Integrity and Security  Concurrency control and recovery
  • 55. So, why don’t scientists use them?  “I tried to use databases in my project, but they were just too [slow | hard-to-use | expensive | complex] . So I use files”.  Gray and Szalay, Where Rubber Meets the Sky: Bridging the Gap Between Databases and Science
  • 56. Some other limitations of RDBMS  Arrays  Hierarchical data
  • 57. Example: Taxonomy of Organisms[8] Hierarchy of categories:  Kingdom - phylum – class – order – family – genus – species  How would you design a relational schema for this? Animals Chordates Vertebrates Arthropods birds insects spiders crustaceans reptiles mammals
  • 58. References 1. http://en.wikipedia.org/wiki/Entity %E2%80%93relationship_model 2. http://simple.wikipedia.org/wiki/Entity-relationship_model 3. https://cs.uwaterloo.ca/~david/cs338/10%20ER%20Model.pdf 4. http://people.cs.pitt.edu/~chang/156/03ERmodel.html 5. http://www.aquafold.com/aquadatastudio/er_modeler.html 6. http://searchdatamanagement.techtarget.com/guide/Limitations-of- entity-relationship-models-in-data-modeling 7. Database System Concepts: Abraham Silberschatz, Henry F. Korth & S., Sudarshan, TATA Mcgraw Hill. 8. Database Systems Concepts, design and Applications 2/e, Singh S. K, PearsonEducation 9. SQL- PL/SQL, Ivan bayross, BPB Publications. 58
  • 59. Images References 1. 1.http://www.tutorialspoint.com/dbms/er_model_basic_concepts.ht m 2. 2.http://www.tutorialspoint.com/dbms/er_diagram_representation.h tm 3. https://www.google.co.in/search? q=ER+Diagram+for+COMPANY+Database+images+in+database +management+system&biw=1024&bih=643&tbm=isch&tbo=u&s ource=univ&sa=X&ei=2a- qVImcMciJuATmvYLYCQ&ved=0CBsQsAQ Chapter 3 59

Notas do Editor

  1. Point out that each e are entity
  2. Show examples of attribute types: composite / simple (atomic) single-valued / multivalued stored / derived key / nonkey.
  3. Point out what each item is
  4. Prepare a discussion
  5. Compare with weak entity with multiple identifying relationships
  6. Note that join can also be thought of as cross product and select