Introduction to Relational Model/2 — Transcript
Full transcript
- 0:00[Music]
- 0:18welcome to module 5
- 0:21of
- 0:21database management systems
- 0:24in the previous module we started
- 0:27discussions on
- 0:28introducing relational model
- 0:32we will conclude that in this module
- 0:36so in the last
- 0:37module we have talked about attributes
- 0:40relational
- 0:41schemas and instances in mathematical
- 0:44form and very importantly we have tried
- 0:47to
- 0:48introduce discuss about the concept of
- 0:50keys
- 0:52in this module we will try to understand
- 0:55more on the relational algebra
- 0:57and familiarize with the operations of
- 1:00relational algebra so these are the
- 1:02different operations that we will
- 1:04ah look at
- 1:06ah select project union and so on some
- 1:08of them are simple set theoretic
- 1:10operations some are newly defined
- 1:12operations and we look at the
- 1:14aggregators
- 1:16so relational operators
- 1:18ok so what is a relation as we have seen
- 1:22already a relation is nothing but a
- 1:23table
- 1:25it has a set of columns
- 1:27and it has a
- 1:28set of rows or records
- 1:31that fill up data according to those
- 1:33columns
- 1:35select is an operation
- 1:38which
- 1:39chooses
- 1:41a
- 1:42subset of rows from a relation
- 1:44based on a certain condition
- 1:47so it is written in terms of
- 1:52in relational algebra we write it with a
- 1:54notion of ah notation of sigma
- 1:58and
- 1:59following a
- 2:00parenthesis we put the name of the
- 2:03relation so we say we are selecting from
- 2:07the relation r
- 2:10and then we put a condition here
- 2:13which is
- 2:14a
- 2:16propositional condition
- 2:25so if
- 2:27for this all rows of r
- 2:29will be checked
- 2:31if a row
- 2:33will satisfy this condition
- 2:37then it will be included in the result
- 2:39if it does not satisfy the condition
- 2:42then it will not be included in the
- 2:44result
- 2:45so let us look at this example
- 2:48so our condition is
- 2:52sorry let us put this back so our
- 2:54condition theta is
- 2:57a is equal to b
- 2:59and
- 3:00d is greater than five
- 3:02so we are saying that
- 3:04that any row to be selected
- 3:06the value of its
- 3:09a attribute should equal the value of
- 3:11its b attribute
- 3:14and when that happens
- 3:16the value of its d attribute must be
- 3:18greater than five
- 3:20so we can easily if we look through this
- 3:22we can easily say by the first condition
- 3:24a equal to b
- 3:25can say that this
- 3:27row
- 3:28does not satisfy this condition because
- 3:31a is alpha and b is beta
- 3:34whereas
- 3:35these three rows
- 3:36satisfy because a is equal to beta
- 3:41then we again look at d
- 3:46we find that this d is less than five so
- 3:50we say this also
- 3:51does not satisfy
- 3:54because it fails the second condition
- 3:56both have to hold
- 3:58so we finally come to that this record
- 4:00and this record
- 4:02are
- 4:03the selected record in the result
- 4:06alpha alpha one seven alpha alpha one
- 4:09seven beta beta twenty three ten beta
- 4:12beta twenty three ten
- 4:14in both of these records a is equal to b
- 4:17in both of these records
- 4:20d is greater than five
- 4:22so selection is a process is a operation
- 4:25which
- 4:26selects a sub set of rows
- 4:30from a table
- 4:32from a relation
- 4:33and creates a new relation
- 4:35based on a selection condition that must
- 4:38be true
- 4:39for all the rows for all the records
- 4:42that have been selected
- 4:45but the set of columns do not change
- 4:47they remain the same
- 4:49so for example if i if ah if in the
- 4:52contrary if we say
- 4:53that
- 4:55sigma
- 4:56a
- 4:58not equal to b r
- 5:00then naturally i will have
- 5:02a
- 5:03relation
- 5:07with fields a b c d
- 5:09and
- 5:12that relation will be
- 5:14only this
- 5:15row
- 5:16because as the only row where a is not
- 5:18equal to b
- 5:23we can i can have a selection saying r
- 5:27where
- 5:30c is greater than zero
- 5:35naturally this will satisfy this will
- 5:37satisfy this will satisfy this will
- 5:39satisfy
- 5:41so this whole relation
- 5:44would be the result of the selection
- 5:47so it is possible that it is not
- 5:48necessary that some rows will have to
- 5:50get eliminated in the result
- 5:53i say that
- 5:55this is
- 6:01is
- 6:05the selection is d is less than one
- 6:08this will fail this will fail this will
- 6:11fail this will fail
- 6:14so all of them will fail
- 6:16so it is possible that the result of an
- 6:18operation could be
- 6:20either the whole relation as we saw last
- 6:22time
- 6:23or a null relation which has where none
- 6:26of the records will
- 6:27feature because none of the records
- 6:29satisfy the condition
- 6:32so there is a basic select operation
- 6:35let us move on look at the next one
- 6:39is called the projection operation so
- 6:41select
- 6:42chooses a subset of the rules
- 6:45projection
- 6:46necessarily
- 6:48chooses projects
- 6:52a
- 6:53set of columns
- 6:55from the original relation
- 6:58so this is
- 6:59quite straight forward to see it is
- 7:01written in terms of
- 7:02this notation pi
- 7:05and then you write the
- 7:08columns that you want in the result
- 7:10of projection
- 7:12so
- 7:13you say this is a c so which means
- 7:16basically
- 7:18the column which is not
- 7:20selected in the projection you can
- 7:22simply forget about that
- 7:24simply erase it
- 7:25if you erase that you get
- 7:27this
- 7:28relation
- 7:30and once you get that
- 7:33please recall that a relation is a set
- 7:36and in a set
- 7:38every element has to be distinct
- 7:40so after erasing b
- 7:44this first and the second row have
- 7:46become identical
- 7:48so naturally
- 7:50both of them cannot be there
- 7:52it will have to be made distinct by
- 7:55erasing any one of them
- 7:57and hence
- 7:58they become one row in the result
- 8:04obviously i can project on
- 8:08any of the in fields singly
- 8:11or all the fields also i can do a
- 8:14projection of
- 8:16of this
- 8:18a b c of r of course that means
- 8:22in this case that will mean that it is a
- 8:24set which is equal to r interval
- 8:27but obviously
- 8:28i must have at least one column at least
- 8:31one attribute to project on i cannot
- 8:33project on a null set of attributes
- 8:35because that does not give me a schema
- 8:38so there will have to be some
- 8:40attribute one or more attribute on which
- 8:43i project
- 8:45so selection and projection
- 8:47ah selection has given me the set of
- 8:50rows to written and projection has given
- 8:52me what are the columns to written in
- 8:54the result and combining them i can do
- 8:57several different
- 8:58operations in a database table which can
- 9:01give me several interesting results
- 9:04ah before proceeding further let us look
- 9:06into some of the
- 9:08typical
- 9:10other operations that relational algebra
- 9:12allows
- 9:13the next one is union
- 9:15given two relations i can take a union
- 9:17this is nothing but a set theoretic
- 9:19union
- 9:20the two relations r and s
- 9:22must have the same set of columns a and
- 9:24b
- 9:26because if the columns are not same then
- 9:28the union does not make sense they
- 9:31because certainly if the columns are
- 9:32different attributes are different
- 9:34their types on type of data values would
- 9:36be different so they cannot be put to a
- 9:38same table
- 9:39so
- 9:40when two relations have the same set of
- 9:42attributes
- 9:43then their instances can be
- 9:46taken a union of
- 9:48so all records that
- 9:51exist in
- 9:53both these relations will be put
- 9:55together into a single table
- 9:57so here
- 10:01alpha one is coming here
- 10:03beta 1 is coming here
- 10:08in terms of relation alpha 1
- 10:10is coming here
- 10:12alpha 2 is coming here
- 10:15beta 1 is coming here
- 10:18beta 3 is coming here
- 10:21and alpha 2 is coming here you can see
- 10:23that
- 10:25this record alpha 2 exist in both the
- 10:28relations
- 10:29and
- 10:30by the set theoretic
- 10:33notion of uniqueness in the union
- 10:36they have to be uniquified
- 10:38so one of them will be removed it does
- 10:41not matter because they are identical
- 10:42anyway
- 10:44so
- 10:45for relations having
- 10:47the same set of attributes we can simply
- 10:49make a
- 10:51union of all its records
- 10:58so other the third operation is ah
- 11:02a fourth operation is
- 11:04doing a set difference its works simply
- 11:07as set theoretic difference
- 11:09again the two relations must have the
- 11:11same set of ah
- 11:13attributes
- 11:14and
- 11:15i can do a difference of
- 11:18r minus s which mean that
- 11:22all tuples which exist in r
- 11:25but do not exist in s
- 11:27will be included
- 11:29so this is included because this is not
- 11:33here
- 11:34but this is not included because it is
- 11:37in s
- 11:39this is included
- 11:41because
- 11:42this is this does not exist
- 11:45in the set s
- 11:47so it is the set so you take the set r
- 11:52and then
- 11:54erase all the records
- 11:56like this which exist in s
- 12:00and you get r minus s so
- 12:03if i
- 12:04look into just to recap
- 12:08if i look into the
- 12:10ah venn diagram then this is
- 12:15these are set r minus s which belongs to
- 12:18r but does not belong to s
- 12:22so this is a fourth operation that
- 12:25one can do
- 12:27with the
- 12:29in relational algebra
- 12:32fifth is a
- 12:34set intersection
- 12:36of two relations
- 12:38so again the two relations need to have
- 12:40the same set of attributes
- 12:42you can take their intersection which is
- 12:44the
- 12:45record which belongs to
- 12:47both
- 12:48it is the record
- 12:50that belongs to
- 12:53both of them
- 12:55and as you
- 12:58are aware now set intersection actually
- 13:01is not a
- 13:02new operation
- 13:04its not a fundamental operation because
- 13:07if i have r if i have s
- 13:09then
- 13:11ah this is
- 13:13r minus s
- 13:16now if i subtract
- 13:18this r minus s which is this set
- 13:22from r
- 13:24which is this bigger set
- 13:27then what will be remaining
- 13:29this is what will be remaining
- 13:34so if i subtract r minus s from r
- 13:37then what will remain is necessarily the
- 13:39intersection of this is our intersection
- 13:42s
- 13:43so set intersection is not a fundamental
- 13:46operation of relational algebra but
- 13:50can be
- 13:51used because
- 13:52it can be expressed in terms of set
- 13:55difference
- 14:04next comes ah how can we join two
- 14:06different relations which have different
- 14:08set of
- 14:10attributes
- 14:11so relation r has a b
- 14:13and relation
- 14:15s as c d e
- 14:16so we can take a cartesian product so
- 14:19taking cartesian product is making all
- 14:21possible combinations so necessarily if
- 14:24since this has two relations and this
- 14:26has three relations
- 14:28so this will have
- 14:30one two three
- 14:32four five six seven
- 14:34a
- 14:35this has four relations so these are
- 14:37eight
- 14:39eight total all possible
- 14:41pairing of relations of r
- 14:44or records of r
- 14:46and records of s are included so that is
- 14:49a cartesian product all possible
- 14:51combinations
- 14:53this is ah this is how we can join two
- 14:55relations but ah certainly
- 14:58what is
- 15:00important is something which we will
- 15:02discuss shortly now in the cartesian
- 15:05product
- 15:06then issue may happen because ah there
- 15:09could be attributes which are common
- 15:11between two relations
- 15:13so if you if two attributes are common
- 15:15when you take cartesian product how do
- 15:16you put their name because as with the
- 15:19example show here between r and s the
- 15:21attribute b is common so how do you take
- 15:24care of that
- 15:25so
- 15:26when the such common names happen then
- 15:28we actually change the name of ah
- 15:32the attribute with the name of the
- 15:34relation so
- 15:36b coming from r will be called r dot b
- 15:38and s b coming from s will be called r
- 15:42dot s
- 15:43and accordingly
- 15:44the
- 15:45relational algebra gives you a way to
- 15:49rename
- 15:50a
- 15:51a a table and put its name differently
- 15:55so this is a given
- 15:58the
- 15:59a
- 16:01this is given by this relation
- 16:04is given by this
- 16:05symbol rho
- 16:07so you can using a relation r
- 16:11you can
- 16:12actually give it a different name s
- 16:15and ah
- 16:17do that in terms of
- 16:19so
- 16:20with that you can actually because
- 16:23otherwise you cannot compute r cross r
- 16:26because if you try to do r cos r
- 16:28then you will have r dot a r dot b and
- 16:31again have r dot a r dot b
- 16:34so you are using this to
- 16:36rename r to s
- 16:38and then compute this so renaming a
- 16:40table is another feature which is
- 16:42provided of course its not a fundamental
- 16:45operation of the algebra but this is ah
- 16:48what makes the any kind of cartesian
- 16:51product possible
- 16:54ah finally
- 16:56we can
- 16:57make composition of operations
- 17:00that for example what we show here
- 17:02is ah we have two relations r and s
- 17:05we have taken a cartesian product and
- 17:08then we have taken a selection
- 17:11so taken a cartesian product of r and s
- 17:13to produce the table as you can see the
- 17:16r cross s and then it did a selection
- 17:19based on a equal to c based on that
- 17:22condition so
- 17:23all these operations can be combined in
- 17:25multiple different ways
- 17:27to give you really complex relational
- 17:30algebra operations
- 17:34ah there is a nice
- 17:37operation which is a derived one which
- 17:38can be written in terms of other
- 17:40operations
- 17:42which is called a natural join which we
- 17:44will use very heavily let me first
- 17:47show you an example of that
- 17:49ah suppose i have two relations ah
- 17:53r and s
- 17:55and what is important is
- 17:57there are some attributes which are
- 18:00common between them
- 18:04now we saw earlier that in in
- 18:08cartesian product in terms of common
- 18:10attributes we basically the attributes
- 18:12got renamed in terms of the table name
- 18:14but this is not what we are looking at
- 18:16in relation natural join
- 18:18what we want to say is if
- 18:21an attribute is common between two two
- 18:24tables
- 18:25then
- 18:27while you join them
- 18:30the records
- 18:32from two fields can be joined if their
- 18:35value
- 18:37on that common attribute is same
- 18:41so it is ah what it tries to do is
- 18:45it tries to make
- 18:47a cartesian product of these two tables
- 18:50first
- 18:51take all possible combinations
- 18:53but then
- 18:55you select only those rows
- 19:00where
- 19:01the values are identical between columns
- 19:06having the same name
- 19:08so for example if you if you if you look
- 19:10into this row and this row
- 19:14so what will happen in in the
- 19:17cartesian product i will have
- 19:23this
- 19:26alpha one alpha a
- 19:28one a alpha
- 19:30let me write it in smaller
- 19:33so i am doing a cartesian product i am
- 19:35looking at this row i am looking at this
- 19:37row so i have a b
- 19:40c d
- 19:41i have b d
- 19:44e
- 19:46and alpha
- 19:47alpha a
- 19:49one e alpha
- 19:54now they match on b
- 19:57they match on d
- 19:59so i will say this is this will get
- 20:01retained
- 20:03but in the cartesian product i will also
- 20:05have the first row
- 20:07of
- 20:09r going with the second row of s
- 20:11alpha one alpha a
- 20:14three a beta
- 20:17here
- 20:18the b does not match
- 20:23d does not does match but the b does not
- 20:26match
- 20:30so this
- 20:31particular entry
- 20:34will not go in the final result
- 20:39so you take the cartesian product
- 20:41and
- 20:42you only retain
- 20:44those
- 20:45rows where
- 20:47the values match for the identically
- 20:50named attribute
- 20:53that is why so you take the artisan
- 20:55product now look at the expression
- 20:58the
- 20:59attributes common attributes are b and c
- 21:02b and d
- 21:04so the b attribute is r dot b
- 21:07and
- 21:08s dot b so we say that in the cartesian
- 21:11product
- 21:12r dot b must equal s dot b
- 21:15the name is common the value will have
- 21:16to be same further
- 21:19similarly d is a common attribute so r
- 21:22dot d value in the r dot d and the value
- 21:24in the s dot d has to be same
- 21:27so based on the
- 21:29cartesian product
- 21:31you do a selection
- 21:33for equality of values on
- 21:37attributes which are identical between
- 21:40the two between the two relations
- 21:43between the two tables
- 21:45this is the final selection
- 21:48as you do that
- 21:52you get a table where there are two b's
- 21:54r dot b s dot b
- 21:56there are two d's r dot d s dot d
- 21:59but according to this selection
- 22:01for all at all records for all rows
- 22:06the value on r dot b and value on s dot
- 22:08b are same
- 22:10value on r dot d and value on r s dot d
- 22:13are same because that is how we have
- 22:14done the selection
- 22:16so there is no
- 22:18reason to keep two b columns or two d
- 22:22columns
- 22:23so now you project
- 22:26based on a
- 22:28r dot b c r dot d and e which means that
- 22:32s dot b
- 22:34and s dot d
- 22:36are left out
- 22:38you do not project them
- 22:41so after
- 22:43you have done this projection
- 22:46you get the final result of the natural
- 22:48join
- 22:49which has
- 22:51a union of all the attributes that the
- 22:54two relations at abcd
- 22:56and bde union is abcde
- 23:00and you have all those records
- 23:05whose
- 23:07values matched
- 23:09on the common attributes between
- 23:11relation r and relation d
- 23:13so you can say that if i now do a
- 23:15selection if i now do a projection on a
- 23:18b c
- 23:20or rather a b c d
- 23:22i will get a subset of r
- 23:24if i do a
- 23:26projection on b d e
- 23:28i will get a subset of s
- 23:31so this is the natural join operation in
- 23:34relational algebra as you can see this
- 23:35is a derived operation
- 23:37because we could use the
- 23:40cartesian product selection and
- 23:42projection to get this but
- 23:44as i tell you we will see see more of
- 23:46this when we look at
- 23:49the ah look at all these different
- 23:52query coding but natural join is one of
- 23:55the most
- 23:56widely used most fundamental relational
- 23:59algebra operation that you will often
- 24:01need beyond selection and projection so
- 24:04these were the six ah operations and the
- 24:07important derived operations of
- 24:09relational algebra besides that
- 24:11relational algebra has some aggregation
- 24:13operators
- 24:15for example ah given a table we could
- 24:19compute the sum of values on a column we
- 24:21could compute average of values max of
- 24:23values mean of values
- 24:25so these somehow aggregate
- 24:27values of multiple rows on a particular
- 24:30column
- 24:32and therefore these are called aggregate
- 24:34operators ah
- 24:36we will see when we talk about sql we
- 24:39will see how these really can be coded
- 24:41in sql and used but these are these
- 24:45become very convenient to use because
- 24:47often we will need to know k if this is
- 24:50ah
- 24:50i mean ah these are the instructors and
- 24:53so let us see which instructor has a
- 24:55maximum load of courses how many based
- 24:59on hours or
- 25:01which instructor has what is the average
- 25:03load on the different instructors and so
- 25:06on so in every possible context
- 25:08different aggregate operators are
- 25:09frequently required and they are also
- 25:11available as operators in most of the
- 25:14pure as well as commercial query
- 25:16languages
- 25:19ah finally to note
- 25:21that
- 25:22relational algebra in relational average
- 25:25every query input is a table
- 25:28and the output is also a table
- 25:32so it is always manipulating one or more
- 25:34tables into a single table that
- 25:37what we are i mean
- 25:38in very simple terms thats a way you can
- 25:40look at it and all data in the output
- 25:43table appears in
- 25:45one of the input tables that is no new
- 25:47data gets generated
- 25:49it is basically
- 25:51taking
- 25:53selecting
- 25:54combining data from different input
- 25:56tables it does not generate a new data
- 25:59that that has to be that is ah if if i
- 26:02see that a v
- 26:04an attribute for a particular row has a
- 26:07value 15
- 26:08then there must be some input table
- 26:10where there is a record where in that
- 26:13field there is an attribute value 50.
- 26:15otherwise this cannot happen
- 26:18again relational algebra is not turing
- 26:20complete in the sense that there are
- 26:22algorithms which cannot be coded in
- 26:24relational algebra
- 26:26we mentioned this earlier too
- 26:28and
- 26:29that is the reason that is a
- 26:30foundational reason of why
- 26:33the sql language commercial sql language
- 26:35which is based on relational algebra is
- 26:37not turing complete either
- 26:39so we might need to use other
- 26:41programming languages along with the
- 26:43relational algebra coding
- 26:45for solving some of the application
- 26:47problems
- 26:49to summarize this is the
- 26:52so this table is what you not only
- 26:54should remember but you should become an
- 26:56expert of
- 26:57in terms of the operators of relational
- 26:59algebra which we will start using very
- 27:01heavily
- 27:03as we start doing the query coding and
- 27:05processing
- 27:06so we talked about selection which takes
- 27:08rows selectively talked about projection
- 27:11which takes out certain columns of a
- 27:13table
- 27:14we talked about cartesian product of two
- 27:17relations which make all possible
- 27:19combined relations
- 27:21we talked about union of
- 27:24records from two tables having identical
- 27:26set of attributes
- 27:28we talked about set difference
- 27:31which again is ah the
- 27:34difference of records
- 27:37of one relation from another
- 27:40given that they have identical
- 27:42set of attributes
- 27:44we have shown that set difference can be
- 27:46used to also
- 27:48compute set intersection so its not in
- 27:51the fundamental operation but is the
- 27:53derived one
- 27:54and we have shown a very interesting ah
- 27:56operation based on cartesian product
- 27:59selection and projection called natural
- 28:02join where two tables can be joined
- 28:04based on
- 28:06one or more common attributes they have
- 28:08now i am sure you have already noted
- 28:11that if i am doing a natural join
- 28:13between two tables which do not have any
- 28:16common attribute then the result is
- 28:18merely the cartesian product because the
- 28:21selection around the cartesian product
- 28:22has no condition to select
- 28:24any
- 28:26ah any of the
- 28:28you know any of the fields any of the
- 28:30rows separately so it merely turns out
- 28:33to be a cartesian product
- 28:39so in this module we have introduced the
- 28:41relational algebra and we have
- 28:44familiarized ourselves with the
- 28:47fundamental and derived operators of
- 28:50relational algebra
- 28:51ah going forward in the next module will
- 28:55take a deeper look into the relational
- 28:57model and start progressing towards the
- 29:01query design and database design
About this transcript
This page contains the full transcript of Introduction to Relational Model/2 by Data Base Management System - IITKGP, generated from the public captions YouTube serves with the video. The transcript has 3,620 words across 730 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.
What you can do with it
Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to translate the transcript into 100+ languages.
Free YouTube transcript tool
YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, translation to 100+ languages, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.