University Assignment: Sets and SQL Operations in Relational Databases

Verified

Added on  2022/09/08

|7
|911
|16
Homework Assignment
AI Summary
This assignment explores the relationship between set theory and relational databases, specifically using SQL. It begins with an introduction to relational databases and SQL, emphasizing how SQL serves as an interface for accessing and manipulating data based on set theory principles. The core of the assignment focuses on demonstrating various set operations such as union, intersection, difference, and Cartesian product, using both mathematical notation (e.g., Venn diagrams) and corresponding SQL queries (T-SQL). Each operation is explained with examples, illustrating how set operations are implemented in SQL. The assignment also touches upon the limitations of SQL in representing certain set operations, such as power set operations. References to relevant literature are also included.
Document Page
Running head: TOPIC 2
TOPIC 2
Name of the Student
Name of the University
Author Note
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
1
A B
TOPIC 2
Introduction:
A relational database is basically a set of tables that grants the access to data and can be
resembled by many ways without the recognition of the database tables. SQL is one of the
standard user and application programming interface (API) of a relational database
(Jananthan et al., 2017). SQL database operations are based on sets and their relationship.
Relational databases operations:
The IN operation in the relational database of T-SQL query is based on a binary relationship
of object to set membership. Venn diagrams are commonly used to graphically represent the
operations of sets (Luo et al., 2018). Let two sets are A = {1,3,6} and B = {3,9,10} then A U
B = {1,3,6,9,10}.
Now, graphically this union operation can be represented as given below by Venn diagrams.
The shaded region represents the set A U B.
Now, in SQL the content of set A and B are fetched through the following SQL query.
SELECT *
FROM A
Document Page
2TOPIC 2
SELECT *
FROM B
Now, the operation of A U B is represented by the following statements in the SQL server.
SELECT *
FROM A
UNION
SELECT *
FROM B
However, the small difference between the T-SQL and the set theory is that in T-SQL the
common elements in two sets can be duplicated in the union set by command UNION ALL
which is not defined in conventional mathematics (Hrbacek & Jech, 2017).
Similarly, the intersection operation in set theory is given by,
A ∩ B = {1,3,6} {3,9,10} = {3}
In SQL server the intersection operation is given by,
SELECT *
FROM A
INTERSECT
SELECT *
FROM B
The difference operation which results the difference of two sets A and B is given by,
Document Page
3TOPIC 2
A \ B = {1,3,6} {3,9,10} = {1,6}
The EXCEPT operator is used in SQL to represent difference between the sets.
SELECT *
FROM A
EXCEPT
SELECT *
FROM B
The Cartesian product is denoted by A x B in set and the result in mathematics is given by,
A x B = {(1,3),(1,9),(1,10),(3,3),(3,9),(3,10),(6,3),(6,9),(6,10)}
The cross join operation in SQL is represented by the following codes.
SELECT *
FROM A
CROSS JOIN B
Alternatively, the cross join operation in SQL can be represented by the following code.
SELECT *
FROM A,B
There are other different operations in sets that can be represented with higher complexity in
the SQL databases like the symmetric difference operation (Goldrei, 2017).
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
4TOPIC 2
The symmetric difference operation is the equivalent operation of a logical XOR. The
operation is denoted by A B. In the set A B the all the elements in A are kept which are
not common in B and the elements in the set B which are not common in A.
The operation A B is graphically represented by,
In the above Venn diagram the set A B is represented by the blue shaded region.
The SQL code for A B operation is given below.
(
SELECT *
FROM A
EXCEPT
SELECT *
FROM B
A B
Document Page
5TOPIC 2
) UNION ALL (
SELECT *
FROM B
EXCEPT
SELECT *
FROM B
)
The same implementation can also be done by SQL by using the IN operator as given by the
following code.
SELECT *
FROM A
WHERE A_Keys NOT IN ( SELECT B_Keys FROM B)
UNION ALL
SELECT *
FROM B
WHERE B_Keys NOT IN (SELECT A_Keys FROM A)
Conclusion:
Although almost all set operations can be done by relational databases like in SQL, however,
some hypothetical relations like the power set operations still cannot be represented by SQL.
These operations are not used in real life appliances and thus relations of those are not yet
implemented in SQL.
Document Page
6TOPIC 2
References:
Goldrei, D. C. (2017). Classic Set Theory: For Guided Independent Study. Routledge.
Hrbacek, K., & Jech, T. (2017). Introduction to set theory, revised and expanded. Crc Press.
Jananthan, H., Zhou, Z., Gadepally, V., Hutchison, D., Kim, S., & Kepner, J. (2017,
December). Polystore mathematics of relational algebra. In 2017 IEEE International
Conference on Big Data (Big Data) (pp. 3180-3189). IEEE.
Luo, S., Gao, Z. J., Gubanov, M., Perez, L. L., & Jermaine, C. (2018). Scalable linear algebra
on a relational database system. IEEE Transactions on Knowledge and Data
Engineering, 31(7), 1224-1238.
chevron_up_icon
1 out of 7
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]