This document provides an overview of relational algebra and SQL. It defines key concepts in relational databases like relations, tuples, attributes, and instances. It describes the five basic relational algebra operations: selection, projection, join, union, and difference. It provides examples of how to express queries using these operations, including compound queries. It then introduces SQL as a language for querying and manipulating data in relational databases, covering commands for table creation, data insertion, deletion, and selection of tuples through queries. It also discusses the use of primary and foreign keys to link relations.
entity relationship diagram or ERD is always required while starting any database project. myassignmenthelp provides help with all kinds of such assignments.
This document discusses converting Scikit-Learn machine learning pipelines to PMML (Predictive Model Markup Language) format. Key points include:
- Scikit-Learn pipelines can be serialized to PMML, allowing models to be deployed anywhere that supports PMML.
- PMML represents the fitted pipeline using standardized data structures, including feature and target field definitions.
- The sklearn2pmml Python library converts Scikit-Learn pipelines to PMML. It handles feature engineering, selection, estimator fitting, and model customization.
- Hyperparameter tuning and algorithm selection tools like GridSearchCV and TPOT can also have their best pipelines exported to PMML.
Fundamentals of database system - Database System Concepts and ArchitectureMustafa Kamel Mohammadi
In this chapter you will learn
DBMS evolution
Data model
Three schema architecture
DBMS language
DBMS interfaces
DBMS components
Classification of DBMS
Object relational and extended relational databasesSuhad Jihad
This document discusses object-relational and extended relational databases. It begins with an introduction and agenda. It then covers database design for ORDBMS, including complex data types, structured types, type inheritance, and array/multiset types. It discusses creating and querying collection-valued attributes. Finally, it covers nesting and unnesting relations to transform between normalized and denormalized forms. The key topics covered in 3 sentences or less are: database design for ORDBMS supports objects, classes, and inheritance; structured types allow user-defined complex attributes; type inheritance and subtables allow modeling specialization hierarchies; and arrays and multisets allow modeling ordered and unordered collections as attributes.
Relational algebra is a formal query language based on relational operations like selection, projection, join, and set operations. It allows users to manipulate and retrieve data from relational databases through algebraic expressions. Key operations include selection to filter rows, projection to select columns, and join to combine relations. Relational algebra provides a foundation for more complex query languages like SQL and is important for understanding how queries are processed and optimized.
The document provides an overview of relational algebra, which is a formal query language used to manipulate data in relational databases. It describes the basic operations in relational algebra, including selection, projection, cross-product, union, intersection, and set difference. It also discusses how these operations can be composed to form more complex queries, and how they allow querying and retrieving data from relational databases in a declarative manner.
This document introduces relational algebra and relational query languages. It discusses how relational algebra uses set operations like selection, projection, join, and division to manipulate relations and retrieve data. It provides examples of expressing various queries in relational algebra and how the operations can be composed to solve more complex queries. Key relational algebra operations and their use in querying relational databases are demonstrated through examples.
entity relationship diagram or ERD is always required while starting any database project. myassignmenthelp provides help with all kinds of such assignments.
This document discusses converting Scikit-Learn machine learning pipelines to PMML (Predictive Model Markup Language) format. Key points include:
- Scikit-Learn pipelines can be serialized to PMML, allowing models to be deployed anywhere that supports PMML.
- PMML represents the fitted pipeline using standardized data structures, including feature and target field definitions.
- The sklearn2pmml Python library converts Scikit-Learn pipelines to PMML. It handles feature engineering, selection, estimator fitting, and model customization.
- Hyperparameter tuning and algorithm selection tools like GridSearchCV and TPOT can also have their best pipelines exported to PMML.
Fundamentals of database system - Database System Concepts and ArchitectureMustafa Kamel Mohammadi
In this chapter you will learn
DBMS evolution
Data model
Three schema architecture
DBMS language
DBMS interfaces
DBMS components
Classification of DBMS
Object relational and extended relational databasesSuhad Jihad
This document discusses object-relational and extended relational databases. It begins with an introduction and agenda. It then covers database design for ORDBMS, including complex data types, structured types, type inheritance, and array/multiset types. It discusses creating and querying collection-valued attributes. Finally, it covers nesting and unnesting relations to transform between normalized and denormalized forms. The key topics covered in 3 sentences or less are: database design for ORDBMS supports objects, classes, and inheritance; structured types allow user-defined complex attributes; type inheritance and subtables allow modeling specialization hierarchies; and arrays and multisets allow modeling ordered and unordered collections as attributes.
Relational algebra is a formal query language based on relational operations like selection, projection, join, and set operations. It allows users to manipulate and retrieve data from relational databases through algebraic expressions. Key operations include selection to filter rows, projection to select columns, and join to combine relations. Relational algebra provides a foundation for more complex query languages like SQL and is important for understanding how queries are processed and optimized.
The document provides an overview of relational algebra, which is a formal query language used to manipulate data in relational databases. It describes the basic operations in relational algebra, including selection, projection, cross-product, union, intersection, and set difference. It also discusses how these operations can be composed to form more complex queries, and how they allow querying and retrieving data from relational databases in a declarative manner.
This document introduces relational algebra and relational query languages. It discusses how relational algebra uses set operations like selection, projection, join, and division to manipulate relations and retrieve data. It provides examples of expressing various queries in relational algebra and how the operations can be composed to solve more complex queries. Key relational algebra operations and their use in querying relational databases are demonstrated through examples.
Relational algebra is a procedural query language used to manipulate relations in a relational database. It consists of operators like select, project, join, union, and set difference. SQL is based on the concepts of relational algebra. Relational algebra expressions specify a sequence of operators to apply to relations in order to retrieve the desired data from the database. Some key operators include selection to filter tuples, projection to select attributes, and join to combine tuples from two relations based on a join condition.
1. The Covers relationship is ternary, involving Employees, Policies, and Dependents relations, while Purchaser and Beneficiary are binary relationships.
2. Ternary relationships impose stronger constraints - a policy must be linked to a specific employee and dependent.
3. The second diagram models the relationships more accurately by separating the purchaser, beneficiary, and policy linkages. This removes ambiguities of the ternary relationship.
Relational query languages allow manipulation and retrieval of data from a database. Relational algebra is the mathematical query language that forms the basis for SQL and implementation. It defines basic operations like selection, projection, join, and set operations that can be composed to express queries. Relational algebra represents queries procedurally and is useful for representing execution plans internally.
Relational algebra allows querying relational databases using a set of operators. Key operators include selection (σ) to filter tuples, projection (π) to select attributes, and join (×) to combine relations. More complex queries can be built by combining multiple operators. The division operator (/) is used to find tuples that have a relationship to all tuples in another relation. While not directly supported, division queries can be computed from other relational algebra operations and their complements.
This document summarizes key points from a lecture on Relational Calculus:
- Relational Calculus is a formal, logical way to define queries by specifying the desired result rather than how to compute it. There are two flavors: Tuple Relational Calculus (TRC) and Domain Relational Calculus (DRC).
- TRC uses tuple variables and allows specifying queries like "Find all sailors with a rating above 7" as {S | S ∈ Sailors ∧ S.rating > 7}.
- Logical operators like ∧, ∨, ¬, ∀, ∃ allow combining atomic formulas to build more complex queries involving joins, projections, and other operations.
The document discusses various concepts related to relational databases including:
- Primary keys uniquely identify rows in a table. Foreign keys match values in other tables' primary keys.
- Relational databases represent data using relations which have a schema and instances consisting of tuples.
- Relational algebra operations like selection, projection, join, etc. allow querying relational data.
Here are the relational algebra and SQL queries for the statements:
1. Find names of sailors who’ve reserved boat #103
[RELational Algebra]
πsname(σbid=103(Sailors ⋈ Reserves))
[SQL]
SELECT sname FROM Sailors, Reserves WHERE sid = sid AND bid = 103
2. Find names of sailors who’ve reserved a red boat
[RELational Algebra]
πsname(σcolor='Red'(Boats ⋈ Reserves ⋈ Sailors)))
[SQL]
SELECT sname FROM Sailors, Reserves, Boats WHERE sid = sid AND bid =
1. The document discusses database design and SQL queries. It reviews relational algebra operators and provides SQL equivalents.
2. Examples are given to demonstrate conceptual evaluation of SQL queries by applying relational algebra operations. Nested queries, aggregate functions, and other SQL concepts are also covered.
3. The document concludes with examples of using aggregate operators like COUNT, SUM, AVG, MAX, and MIN in SQL queries.
The document summarizes a lecture on relational algebra, which is a formal query language for relational databases. It describes the basic relational algebra operations - selection, projection, cross product, set difference, and union. It provides examples of how to use these operations to answer queries by selecting, combining, and relating tables of data. It also discusses additional compound operations like join, intersection, and division that can be expressed using the basic operations.
The document summarizes a lecture on relational algebra, which is a formal query language for relational databases. It describes the basic relational algebra operations - selection, projection, cross product, set difference, and union. It provides examples of how to use each operation and how to express more complex queries using multiple operations or compound operators like join and division.
The document discusses relational algebra operations. It defines the select, project, cartesian product, and join operations. It provides examples of relational algebra expressions using these operations on sample relations to retrieve specific tuples based on conditions.
The document provides an introduction to relational databases and relational database management systems (RDBMS). It describes key concepts like tables, rows, columns, primary keys, foreign keys, and relationships. It also explains common relational algebra operations like selection, projection, join, and set operations. Indexes are discussed as a way to improve query performance. The document highlights why RDBMS are useful but also notes some limitations for scientific applications.
The document provides an introduction to relational databases and relational database management systems (RDBMS). It discusses key concepts like tables, schemas, primary keys, foreign keys, and relationships. It also covers relational algebra operations like selection, projection, joins, and set operations. Finally, it discusses SQL and features of RDBMS like views, indexes, and their benefits and limitations for scientific data.
Relational algebra and calculus are formal query languages used to manipulate and retrieve data from relational databases. Relational algebra uses algebraic operations like selection, projection, join, etc. to represent queries procedurally. Relational calculus allows users to describe what data is wanted declaratively using logic-based formulas with variables, quantifiers and predicates over relation instances. Both have free and bound variables, and queries return tuples that satisfy the formulas by assigning constants to free variables.
Relational algebra is the basis for query languages like SQL and is useful for representing query execution plans. It defines basic operations like selection, projection, join, and set operations that allow querying and manipulating data in relational databases. Relational algebra is important as a theoretical foundation, for specifying query optimization plans, and because understanding it helps write correct SQL queries.
This document provides an overview of relational algebra and SQL. It discusses key concepts such as relational query languages, relational algebra operators like selection, projection, join, and division. It also covers how SQL corresponds to relational algebra, with SQL using a declarative syntax while relational algebra is procedural. Common queries involving joins, aggregates, and other features are demonstrated in both SQL and equivalent relational algebra expressions.
Relational algebra is a formal query language based on relational operations like selection, projection, join, and set operations. It allows users to manipulate and retrieve data from relational databases. Relational algebra expressions can represent execution plans and be composed together for complex queries. Queries can often be expressed in multiple ways using different relational algebra operations, and a query optimizer should select the most efficient expression.
Lecture 06 relational algebra and calculusemailharmeet
The document discusses data manipulation languages (DML) for databases. There are two main types of DML: navigational/procedural and non-navigational/non-procedural. Relational algebra is a non-navigational DML defined by Codd that uses algebraic operations like selection, projection, join, etc. on tables. Relational calculus is also a non-navigational DML that defines new relations in terms of predicates on tuple variables ranging over named relations.
The document discusses query processing in distributed databases. It describes the key steps of query processing as decomposition, localization, and optimization. Decomposition breaks queries into algebraic query trees. Localization rewrites the trees to replace relations with fragments based on fragmentation schemes. Optimization chooses the lowest cost query execution plan based on a cost model and localized query trees. The document provides examples of localization rules and parallel/distributed query operations like sorting, joining, and aggregation.
Relational algebra is a procedural query language used to manipulate relations in a relational database. It consists of operators like select, project, join, union, and set difference. SQL is based on the concepts of relational algebra. Relational algebra expressions specify a sequence of operators to apply to relations in order to retrieve the desired data from the database. Some key operators include selection to filter tuples, projection to select attributes, and join to combine tuples from two relations based on a join condition.
1. The Covers relationship is ternary, involving Employees, Policies, and Dependents relations, while Purchaser and Beneficiary are binary relationships.
2. Ternary relationships impose stronger constraints - a policy must be linked to a specific employee and dependent.
3. The second diagram models the relationships more accurately by separating the purchaser, beneficiary, and policy linkages. This removes ambiguities of the ternary relationship.
Relational query languages allow manipulation and retrieval of data from a database. Relational algebra is the mathematical query language that forms the basis for SQL and implementation. It defines basic operations like selection, projection, join, and set operations that can be composed to express queries. Relational algebra represents queries procedurally and is useful for representing execution plans internally.
Relational algebra allows querying relational databases using a set of operators. Key operators include selection (σ) to filter tuples, projection (π) to select attributes, and join (×) to combine relations. More complex queries can be built by combining multiple operators. The division operator (/) is used to find tuples that have a relationship to all tuples in another relation. While not directly supported, division queries can be computed from other relational algebra operations and their complements.
This document summarizes key points from a lecture on Relational Calculus:
- Relational Calculus is a formal, logical way to define queries by specifying the desired result rather than how to compute it. There are two flavors: Tuple Relational Calculus (TRC) and Domain Relational Calculus (DRC).
- TRC uses tuple variables and allows specifying queries like "Find all sailors with a rating above 7" as {S | S ∈ Sailors ∧ S.rating > 7}.
- Logical operators like ∧, ∨, ¬, ∀, ∃ allow combining atomic formulas to build more complex queries involving joins, projections, and other operations.
The document discusses various concepts related to relational databases including:
- Primary keys uniquely identify rows in a table. Foreign keys match values in other tables' primary keys.
- Relational databases represent data using relations which have a schema and instances consisting of tuples.
- Relational algebra operations like selection, projection, join, etc. allow querying relational data.
Here are the relational algebra and SQL queries for the statements:
1. Find names of sailors who’ve reserved boat #103
[RELational Algebra]
πsname(σbid=103(Sailors ⋈ Reserves))
[SQL]
SELECT sname FROM Sailors, Reserves WHERE sid = sid AND bid = 103
2. Find names of sailors who’ve reserved a red boat
[RELational Algebra]
πsname(σcolor='Red'(Boats ⋈ Reserves ⋈ Sailors)))
[SQL]
SELECT sname FROM Sailors, Reserves, Boats WHERE sid = sid AND bid =
1. The document discusses database design and SQL queries. It reviews relational algebra operators and provides SQL equivalents.
2. Examples are given to demonstrate conceptual evaluation of SQL queries by applying relational algebra operations. Nested queries, aggregate functions, and other SQL concepts are also covered.
3. The document concludes with examples of using aggregate operators like COUNT, SUM, AVG, MAX, and MIN in SQL queries.
The document summarizes a lecture on relational algebra, which is a formal query language for relational databases. It describes the basic relational algebra operations - selection, projection, cross product, set difference, and union. It provides examples of how to use these operations to answer queries by selecting, combining, and relating tables of data. It also discusses additional compound operations like join, intersection, and division that can be expressed using the basic operations.
The document summarizes a lecture on relational algebra, which is a formal query language for relational databases. It describes the basic relational algebra operations - selection, projection, cross product, set difference, and union. It provides examples of how to use each operation and how to express more complex queries using multiple operations or compound operators like join and division.
The document discusses relational algebra operations. It defines the select, project, cartesian product, and join operations. It provides examples of relational algebra expressions using these operations on sample relations to retrieve specific tuples based on conditions.
The document provides an introduction to relational databases and relational database management systems (RDBMS). It describes key concepts like tables, rows, columns, primary keys, foreign keys, and relationships. It also explains common relational algebra operations like selection, projection, join, and set operations. Indexes are discussed as a way to improve query performance. The document highlights why RDBMS are useful but also notes some limitations for scientific applications.
The document provides an introduction to relational databases and relational database management systems (RDBMS). It discusses key concepts like tables, schemas, primary keys, foreign keys, and relationships. It also covers relational algebra operations like selection, projection, joins, and set operations. Finally, it discusses SQL and features of RDBMS like views, indexes, and their benefits and limitations for scientific data.
Relational algebra and calculus are formal query languages used to manipulate and retrieve data from relational databases. Relational algebra uses algebraic operations like selection, projection, join, etc. to represent queries procedurally. Relational calculus allows users to describe what data is wanted declaratively using logic-based formulas with variables, quantifiers and predicates over relation instances. Both have free and bound variables, and queries return tuples that satisfy the formulas by assigning constants to free variables.
Relational algebra is the basis for query languages like SQL and is useful for representing query execution plans. It defines basic operations like selection, projection, join, and set operations that allow querying and manipulating data in relational databases. Relational algebra is important as a theoretical foundation, for specifying query optimization plans, and because understanding it helps write correct SQL queries.
This document provides an overview of relational algebra and SQL. It discusses key concepts such as relational query languages, relational algebra operators like selection, projection, join, and division. It also covers how SQL corresponds to relational algebra, with SQL using a declarative syntax while relational algebra is procedural. Common queries involving joins, aggregates, and other features are demonstrated in both SQL and equivalent relational algebra expressions.
Relational algebra is a formal query language based on relational operations like selection, projection, join, and set operations. It allows users to manipulate and retrieve data from relational databases. Relational algebra expressions can represent execution plans and be composed together for complex queries. Queries can often be expressed in multiple ways using different relational algebra operations, and a query optimizer should select the most efficient expression.
Lecture 06 relational algebra and calculusemailharmeet
The document discusses data manipulation languages (DML) for databases. There are two main types of DML: navigational/procedural and non-navigational/non-procedural. Relational algebra is a non-navigational DML defined by Codd that uses algebraic operations like selection, projection, join, etc. on tables. Relational calculus is also a non-navigational DML that defines new relations in terms of predicates on tuple variables ranging over named relations.
The document discusses query processing in distributed databases. It describes the key steps of query processing as decomposition, localization, and optimization. Decomposition breaks queries into algebraic query trees. Localization rewrites the trees to replace relations with fragments based on fragmentation schemes. Optimization chooses the lowest cost query execution plan based on a cost model and localized query trees. The document provides examples of localization rules and parallel/distributed query operations like sorting, joining, and aggregation.
Similar to Database managment System Relational Algebra (20)
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsVictor Morales
K8sGPT is a tool that analyzes and diagnoses Kubernetes clusters. This presentation was used to share the requirements and dependencies to deploy K8sGPT in a local environment.
ACEP Magazine edition 4th launched on 05.06.2024Rahul
This document provides information about the third edition of the magazine "Sthapatya" published by the Association of Civil Engineers (Practicing) Aurangabad. It includes messages from current and past presidents of ACEP, memories and photos from past ACEP events, information on life time achievement awards given by ACEP, and a technical article on concrete maintenance, repairs and strengthening. The document highlights activities of ACEP and provides a technical educational article for members.
Using recycled concrete aggregates (RCA) for pavements is crucial to achieving sustainability. Implementing RCA for new pavement can minimize carbon footprint, conserve natural resources, reduce harmful emissions, and lower life cycle costs. Compared to natural aggregate (NA), RCA pavement has fewer comprehensive studies and sustainability assessments.
Embedded machine learning-based road conditions and driving behavior monitoringIJECEIAES
Car accident rates have increased in recent years, resulting in losses in human lives, properties, and other financial costs. An embedded machine learning-based system is developed to address this critical issue. The system can monitor road conditions, detect driving patterns, and identify aggressive driving behaviors. The system is based on neural networks trained on a comprehensive dataset of driving events, driving styles, and road conditions. The system effectively detects potential risks and helps mitigate the frequency and impact of accidents. The primary goal is to ensure the safety of drivers and vehicles. Collecting data involved gathering information on three key road events: normal street and normal drive, speed bumps, circular yellow speed bumps, and three aggressive driving actions: sudden start, sudden stop, and sudden entry. The gathered data is processed and analyzed using a machine learning system designed for limited power and memory devices. The developed system resulted in 91.9% accuracy, 93.6% precision, and 92% recall. The achieved inference time on an Arduino Nano 33 BLE Sense with a 32-bit CPU running at 64 MHz is 34 ms and requires 2.6 kB peak RAM and 139.9 kB program flash memory, making it suitable for resource-constrained embedded systems.
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...IJECEIAES
Medical image analysis has witnessed significant advancements with deep learning techniques. In the domain of brain tumor segmentation, the ability to
precisely delineate tumor boundaries from magnetic resonance imaging (MRI)
scans holds profound implications for diagnosis. This study presents an ensemble convolutional neural network (CNN) with transfer learning, integrating
the state-of-the-art Deeplabv3+ architecture with the ResNet18 backbone. The
model is rigorously trained and evaluated, exhibiting remarkable performance
metrics, including an impressive global accuracy of 99.286%, a high-class accuracy of 82.191%, a mean intersection over union (IoU) of 79.900%, a weighted
IoU of 98.620%, and a Boundary F1 (BF) score of 83.303%. Notably, a detailed comparative analysis with existing methods showcases the superiority of
our proposed model. These findings underscore the model’s competence in precise brain tumor localization, underscoring its potential to revolutionize medical
image analysis and enhance healthcare outcomes. This research paves the way
for future exploration and optimization of advanced CNN models in medical
imaging, emphasizing addressing false positives and resource efficiency.
Literature Review Basics and Understanding Reference Management.pptxDr Ramhari Poudyal
Three-day training on academic research focuses on analytical tools at United Technical College, supported by the University Grant Commission, Nepal. 24-26 May 2024
Understanding Inductive Bias in Machine LearningSUTEJAS
This presentation explores the concept of inductive bias in machine learning. It explains how algorithms come with built-in assumptions and preferences that guide the learning process. You'll learn about the different types of inductive bias and how they can impact the performance and generalizability of machine learning models.
The presentation also covers the positive and negative aspects of inductive bias, along with strategies for mitigating potential drawbacks. We'll explore examples of how bias manifests in algorithms like neural networks and decision trees.
By understanding inductive bias, you can gain valuable insights into how machine learning models work and make informed decisions when building and deploying them.
2. Relational Database: Definitions
• Relational database: a set of relations.
• Relation: made up of 2 parts:
– Schema : specifies name of relation, plus name
and type of each column.
• E.g. Students(sid: string, name: string, login: string, age:
integer, gpa: real)
– Instance : a table, with rows and columns.
• #rows = cardinality
• #fields = degree / arity
• Can think of a relation as a set of rows or
tuples.
– i.e., all rows are distinct
3. Ex: Instance of Students Relation
sid name login age gpa
53666 Jones jones@cs 18 3.4
53688 Smith smith@eecs 18 3.2
53650 Smith smith@math 19 3.8
• Cardinality = 3, arity = 5 , all rows distinct
• Do all values in each column of a relation instance
have to be distinct?
4. Relational Query Languages
• Query languages: Allow manipulation and retrieval of
data from a database.
• Relational model supports simple, powerful QLs:
– Strong formal foundation based on logic.
– Allows for much optimization.
• Query Languages != programming languages!
– QLs not intended to be used for complex calculations.
– QLs support easy, efficient access to large data sets.
5. Preliminaries
• A query is applied to relation instances, and the
result of a query is also a relation instance.
6. Relational Algebra: 5 Basic Operations
• Selection ( s ) Selects a subset of rows from relation
(horizontal).
• Projection ( p ) Retains only wanted columns from relation
(vertical).
• Cross-product ( ) Allows us to combine two relations.
• Set-difference ( — ) Tuples in r1, but not in r2.
• Union ( ) Tuples in r1 or in r2.
Since each operation returns a relation, operations can be
composed! (Algebra is “closed”.)
7. sid sname rating age
22 dustin 7 45.0
31 lubber 8 55.5
58 rusty 10 35.0
sid sname rating age
28 yuppy 9 35.0
31 lubber 8 55.5
44 guppy 5 35.0
58 rusty 10 35.0
sid bid day
22 101 10/10/96
58 103 11/12/96
R1
S1
S2
bid bname color
101 Interlake blue
102 Interlake red
103 Clipper green
104 Marine red
Boats
Example Instances
8. Projection (p)
page S( )2• Examples: ;
• Retains only attributes that are in the “projection list”.
• Schema of result:
– exactly the fields in the projection list, with the same names that they
had in the input relation.
• Projection operator has to eliminate duplicates (How do they
arise? Why remove them?)
– Note: real systems typically don’t do duplicate elimination unless the
user explicitly asks for it. (Why not?)
psname rating
S
,
( )2
10. Selection (s)
srating
S
8
2( )
sname rating
yuppy 9
rusty 10
p ssname rating rating
S
,
( ( ))
8
2
• Selects rows that satisfy selection condition.
• Result is a relation.
Schema of result is same as that of the input relation.
• Do we need to do duplicate elimination?
sid sname rating age
28 yuppy 9 35.0
31 lubber 8 55.5
44 guppy 5 35.0
58 rusty 10 35.0
11. Union and Set-Difference
• Both of these operations take two input relations,
which must be union-compatible:
– Same number of fields.
– `Corresponding’ fields have the same type.
• For which, if any, is duplicate elimination required?
14. Cross-Product
• S1 R1: Each row of S1 paired with each row of R1.
• Q: How many rows in the result?
• Result schema has one field per field of S1 and R1,
with field names `inherited’ if possible.
– May have a naming conflict: Both S1 and R1 have a field
with the same name.
– In this case, can use the renaming operator:
( ( , ), )C sid sid S R1 1 5 2 1 1
16. Compound Operator: Intersection
• In addition to the 5 basic operators, there are several
additional “Compound Operators”
– These add no computational power to the language, but are
useful shorthands.
– Can be expressed solely with the basic ops.
• Intersection takes two input relations, which must be
union-compatible.
• Q: How to express it using basic operators?
R S = R (R S)
18. Other Types of Joins
• Condition Join (or “theta-join”):
• Result schema same as that of cross-product.
• May have fewer tuples than cross-product.
• Equi-Join: Special case: condition c contains only
conjunction of equalities.
R c S c R S s ( )
(sid) sname rating age (sid) bid day
22 dustin 7 45.0 58 103 11/12/96
31 lubber 8 55.5 58 103 11/12/96
11
.1.1
RS
sidRsidS
19. Examples
sid sname rating age
22 dustin 7 45.0
31 lubber 8 55.5
58 rusty 10 35.0
bid bname color
101 Interlake Blue
102 Interlake Red
103 Clipper Green
104 Marine Red
sid bid day
22 101 10/10/96
58 103 11/12/96
Reserves
Sailors
Boats
20. Find names of sailors who’ve reserved boat #103
• Solution 1: p ssname bid
serves Sailors(( Re ) )
103
• Solution 2: p ssname bid
serves Sailors( (Re ))
103
21. Find names of sailors who’ve reserved a red boat
• Information about boat color only available in
Boats; so need an extra join:
p ssname color red
Boats serves Sailors((
' '
) Re )
A more efficient solution:
p p p ssname sid bid color red
Boats s Sailors( ((
' '
) Re ) )
A query optimizer can find this given the first solution!
22. Find sailors who’ve reserved a red boat or a green
boat
• Can identify all red or green boats, then find
sailors who’ve reserved one of these boats:
s( ,(
' ' ' '
))Tempboats
color red color green
Boats
p sname Tempboats serves Sailors( Re )
23. Find sailors who’ve reserved a red and a green boat
• Cut-and-paste previous slide?
(Tempboats,(s
color'red'color'green'
Boats))
p sname Tempboats serves Sailors( Re )
24. Find sailors who’ve reserved a red and a green boat
• Previous approach won’t work! Must identify
sailors who’ve reserved red boats, sailors who’ve
reserved green boats, then find the intersection
(note that sid is a key for Sailors):
p s( , ((
' '
) Re ))Tempred
sid color red
Boats serves
p sname Tempred Tempgreen Sailors(( ) )
p s( , ((
' '
) Re ))Tempgreen
sid color green
Boats serves
25. Summary
• Relational Algebra: a small set of operators
mapping relations to relations
– Operational, in the sense that you specify the
explicit order of operations
– A closed set of operators! Can mix and match.
• Basic ops include: s, p, , , —
• Important compound ops: ,
26. SQL - A language for Relational DBs
• SQL (a.k.a. “Sequel”), standard
language
• Data Definition Language (DDL)
– create, modify, delete relations
– specify constraints
– administer users, security, etc.
• Data Manipulation Language (DML)
– Specify queries to find tuples that satisfy
criteria
– add, modify, remove tuples
27. SQL Overview
• CREATE TABLE <name> ( <field> <domain>, … )
• INSERT INTO <name> (<field names>)
VALUES (<field values>)
• DELETE FROM <name>
WHERE <condition>
• UPDATE <name>
SET <field name> = <value>
WHERE <condition>
• SELECT <fields>
FROM <name>
WHERE <condition>
28. Creating Relations in SQL
• Creates the Students relation.
– Note: the type (domain) of each field is
specified, and enforced by the DBMS
whenever tuples are added or modified.
CREATE TABLE Students
(sid CHAR(20),
name CHAR(20),
login CHAR(10),
age INTEGER,
gpa FLOAT)
29. Table Creation (continued)
• Another example: the Enrolled table
holds information about courses
students take.
CREATE TABLE Enrolled
(sid CHAR(20),
cid CHAR(20),
grade CHAR(2))
30. Adding and Deleting Tuples
• Can insert a single tuple using:
INSERT INTO Students (sid, name, login, age, gpa)
VALUES (‘53688’, ‘Smith’, ‘smith@ee’, 18, 3.2)
• Can delete all tuples satisfying some condition
(e.g., name = Smith):
DELETE
FROM Students S
WHERE S.name = ‘Smith’
Powerful variants of these commands are available;
more later!
31. Keys
• Keys are a way to associate tuples in
different relations
• Keys are one form of integrity constraint
(IC)
sid name login age gpa
53666 Jones jones@cs 18 3.4
53688 Smith smith@eecs 18 3.2
53650 Smith smith@math 19 3.8
sid cid grade
53666 Carnatic101 C
53666 Reggae203 B
53650 Topology112 A
53666 History105 B
Enrolled Students
PRIMARY KeyFOREIGN Key
32. Primary Keys
• A set of fields is a superkey if:
– No two distinct tuples can have same values in all key fields
• A set of fields is a key for a relation if :
– It is a superkey
– No subset of the fields is a superkey
• what if >1 key for a relation?
– One of the keys is chosen (by DBA) to be the primary key.
Other keys are called candidate keys.
• E.g.
– sid is a key for Students.
– What about name?
– The set {sid, gpa} is a superkey.
33. Primary and Candidate Keys in SQL
• Possibly many candidate keys (specified using
UNIQUE), one of which is chosen as the primary key.
• Keys must be used carefully!
• “For a given student and course, there is a single grade.”
“Students can take only one course, and no two students
in a course receive the same grade.”
CREATE TABLE Enrolled
(sid CHAR(20)
cid CHAR(20),
grade CHAR(2),
PRIMARY KEY (sid,cid))
CREATE TABLE Enrolled
(sid CHAR(20)
cid CHAR(20),
grade CHAR(2),
PRIMARY KEY (sid),
UNIQUE (cid, grade))
vs.
34. Foreign Keys, Referential Integrity
• Foreign key: Set of fields in one relation
that is used to `refer’ to a tuple in another
relation.
– Must correspond to the primary key of the other
relation.
– Like a `logical pointer’.
• If all foreign key constraints are enforced,
referential integrity is achieved (i.e., no
dangling references.)
35. Foreign Keys in SQL
• E.g. Only students listed in the Students relation
should be allowed to enroll for courses.
– sid is a foreign key referring to Students:
CREATE TABLE Enrolled
(sid CHAR(20),cid CHAR(20),grade CHAR(2),
PRIMARY KEY (sid,cid),
FOREIGN KEY (sid) REFERENCES Students )
sid cid grade
53666 Carnatic101 C
53666 Reggae203 B
53650 Topology112 A
53666 History105 B
Enrolled
sid name login age gpa
53666 Jones jones@cs 18 3.4
53688 Smith smith@eecs 18 3.2
53650 Smith smith@math 19 3.8
Students
11111 English102 A
36. Enforcing Referential Integrity
• Consider Students and Enrolled; sid in Enrolled is a
foreign key that references Students.
• What should be done if an Enrolled tuple with a non-
existent student id is inserted? (Reject it!)
• What should be done if a Students tuple is deleted?
– Also delete all Enrolled tuples that refer to it?
– Disallow deletion of a Students tuple that is referred to?
– Set sid in Enrolled tuples that refer to it to a default sid?
– (In SQL, also: Set sid in Enrolled tuples that refer to it to a
special value null, denoting `unknown’ or `inapplicable’.)
• Similar issues arise if primary key of Students tuple is
updated.
37. Integrity Constraints (ICs)
• IC: condition that must be true for any
instance of the database; e.g., domain
constraints.
– ICs are specified when schema is defined.
– ICs are checked when relations are modified.
• A legal instance of a relation is one that
satisfies all specified ICs.
– DBMS should not allow illegal instances.
• If the DBMS checks ICs, stored data is more
faithful to real-world meaning.
– Avoids data entry errors, too!
38. Where do ICs Come From?
• ICs are based upon the semantics of the real-world
that is being described in the database relations.
• We can check a database instance to see if an IC is
violated, but we can NEVER infer that an IC is true by
looking at an instance.
– An IC is a statement about all possible instances!
– From example, we know name is not a key, but the
assertion that sid is a key is given to us.
• Key and foreign key ICs are the most common; more
general ICs supported too.
• In the real world, sometimes the constraint should
hold but doesn’t --> data cleaning!
39. Relational Query Languages
• A major strength of the relational model:
supports simple, powerful querying of data.
• Queries can be written intuitively, and the
DBMS is responsible for efficient evaluation.
– The key: precise semantics for relational queries.
– Allows the optimizer to extensively re-order
operations, and still ensure that the answer does
not change.
40. The SQL Query Language
• The most widely used relational query
language.
– Current std is SQL:2003; SQL92 is a basic subset
• To find all 18 year old students, we can write:
SELECT *
FROM Students S
WHERE S.age=18
• To find just names and logins, replace the first line:
SELECT S.name, S.login
sid name age gpa
53666 Jones 18 3.4
53688 Smith 18 3.2
53650 Smith
login
jones@cs
smith@ee
smith@math 19 3.8
41. Querying Multiple Relations
• What does the following query compute?
SELECT S.name, E.cid
FROM Students S, Enrolled E
WHERE S.sid=E.sid AND E.grade='A'
sid cid grade
53831 Carnatic101 C
53831 Reggae203 B
53650 Topology112 A
53666 History105 B
Given the following instance of
Enrolled
S.name E.cid
Smith Topology112
we get:
42. Semantics of a Query
• A conceptual evaluation method for the previous
query:
1. do FROM clause: compute cross-product of Students and
Enrolled
2. do WHERE clause: Check conditions, discard tuples that fail
3. do SELECT clause: Delete unwanted fields
• Remember, this is conceptual. Actual evaluation will
be much more efficient, but must produce the same
answers.
43. Cross-product of Students and Enrolled Instances
S.sid S.name S.login S.age S.gpa E.sid E.cid E.grade
53666 Jones jones@cs 18 3.4 53831 Carnatic101 C
53666 Jones jones@cs 18 3.4 53832 Reggae203 B
53666 Jones jones@cs 18 3.4 53650 Topology112 A
53666 Jones jones@cs 18 3.4 53666 History105 B
53688 Smith smith@ee 18 3.2 53831 Carnatic101 C
53688 Smith smith@ee 18 3.2 53831 Reggae203 B
53688 Smith smith@ee 18 3.2 53650 Topology112 A
53688 Smith smith@ee 18 3.2 53666 History105 B
53650 Smith smith@math 19 3.8 53831 Carnatic101 C
53650 Smith smith@math 19 3.8 53831 Reggae203 B
53650 Smith smith@math 19 3.8 53650 Topology112 A
53650 Smith smith@math 19 3.8 53666 History105 B
44. Relational Model: Summary
• A tabular representation of data.
• Simple and intuitive, currently the most widely used
– Object-relational support in most products
– XML support added in SQL:2003, most systems
• Integrity constraints can be specified by the DBA,
based on application semantics. DBMS checks for
violations.
– Two important ICs: primary and foreign keys
– In addition, we always have domain constraints.
• Powerful query languages exist.
– SQL is the standard commercial one
• DDL - Data Definition Language
• DML - Data Manipulation Language
46. Databases for Programmers
• Programmers think about objects
(structs)
– Nested and interleaved
• Often want to “persist” these things
• Options
– encode opaquely and store
– translate to a structured form
• relational DB, XML file
– pros and cons?
47. YUCK!!
• How do I “relationalize” my objects?
• Have to write a converter for each
class?
• Think about when to save things into
the DB?
• Good news:
– Can all be automated
– With varying amounts of trouble
49. Details, details
• We have to map this down to tables
• Which table holds which class of object?
• What about relationships?
• Solution #1: Declarative Configuration
– Write a description file (often in XML)
• E.g. Enterprise Java Beans (EJBs)
• Solution #2: Convention
– Agree to use some conventions
• E.g. Rails
50. Ruby on Rails
• Ruby: an OO scripting language
– and a pretty nice one, too
• Rails: a framework for web apps
– “convention over configuration”
• great for standard web-app stuff!
– allows overriding as needed
• Very ER-like
51. Rails and ER
• Models
– Employees
– Departments
lot
name
Employees
ssn
Works_In
since
dname
budgetdid
Departments