YouTube2Text

Formal Relational Query Languages — Transcript

by Data Base Management System - IITKGP · 4,166 words · 843 segments · language en · Watch on YouTube

Full transcript

  1. 0:00[Music]
  2. 0:17welcome to module 12
  3. 0:19of database management systems
  4. 0:23in this module
  5. 0:25we will
  6. 0:26talk about
  7. 0:28the formal
  8. 0:29relational query languages
  9. 0:33in the last couple of modules we have
  10. 0:36discussed about
  11. 0:37sql at length
  12. 0:39introducing it
  13. 0:41dealing with the intermediate level of
  14. 0:43sql
  15. 0:45features and then
  16. 0:47exposing to
  17. 0:49some of the advanced features as well
  18. 0:53the foundational mathematical model
  19. 0:56of
  20. 0:57sql the query languages
  21. 0:59are to be discussed in this
  22. 1:02present
  23. 1:03module
  24. 1:05so this is what
  25. 1:07we had done in the last module
  26. 1:10in the current one we will work to
  27. 1:13understand the formal query languages
  28. 1:16primarily through relational algebra
  29. 1:19and then we will also take
  30. 1:22a look into some of the calculus
  31. 1:25aspects
  32. 1:27tuple relational calculus and domain
  33. 1:29relational calculus
  34. 1:31and we will
  35. 1:33show by example the equivalence between
  36. 1:37the algebra and the two calculus
  37. 1:42so
  38. 1:43formal relational query languages
  39. 1:46are of three types one is known as
  40. 1:50relational algebra
  41. 1:52this is procedural in nature
  42. 1:56so we specify
  43. 1:58what operations need to be done to
  44. 2:01achieve the result
  45. 2:04and the whole formulation is based on
  46. 2:07set algebra
  47. 2:10the second
  48. 2:11formal
  49. 2:13query language is tuple relational
  50. 2:15calculus
  51. 2:17which is non-procedural and is based on
  52. 2:19predicate calculus
  53. 2:22the third one the domain relational
  54. 2:24calculus is a
  55. 2:26minor variant of the tuple relational
  56. 2:28calculus is and is also non procedural
  57. 2:31and
  58. 2:32predicate calculus based
  59. 2:35so we will start with the relational
  60. 2:37algebra
  61. 2:41in the relational algebra
  62. 2:43it was created by
  63. 2:46edgar f cord
  64. 2:48at ibm in nineteen
  65. 2:50seventies
  66. 2:52so you can see that it is ah quite an
  67. 2:54old formulation
  68. 2:56it is a procedural language
  69. 2:58it has six operators we have taken
  70. 3:02a quick view of these earlier in this
  71. 3:04module we will look at them at length
  72. 3:07the select project union
  73. 3:10set difference cartesian product and
  74. 3:13rename
  75. 3:14we will also look at few derived
  76. 3:16operations like
  77. 3:18intersection and division which can be
  78. 3:21expressed in terms of these basic
  79. 3:23operators
  80. 3:24and
  81. 3:26each one of these operators can take one
  82. 3:28or two relations
  83. 3:30as input and they produce one relation
  84. 3:33as a result
  85. 3:36so we start with the select operation
  86. 3:38which
  87. 3:39you know has a notation sigma
  88. 3:42subscript p is a predicate
  89. 3:44it is called the selection predicate and
  90. 3:46within parenthesis we have a relation r
  91. 3:49on which this predicate applies
  92. 3:53so it is defined as
  93. 3:58a set where
  94. 4:01you collect
  95. 4:03all the tuples all the rows
  96. 4:06designated by t
  97. 4:08and
  98. 4:09you specify that t belongs to the
  99. 4:11relation
  100. 4:12so it already exist in that relation
  101. 4:16and
  102. 4:17it satisfies
  103. 4:19the particular selection predicate
  104. 4:21so
  105. 4:22any tuple that satisfies this predicate
  106. 4:25is included in the result
  107. 4:27any that does not satisfy is excluded
  108. 4:30from the result
  109. 4:32p here particularly is a propositional
  110. 4:35calculus formula
  111. 4:38or expression
  112. 4:40where we have different terms that are
  113. 4:43connected by conjunction or and
  114. 4:47disjunction or or
  115. 4:49or negation
  116. 4:51or not
  117. 4:53and each term by itself could be
  118. 4:56something like this it is an attribute
  119. 4:58operate an attribute where operators are
  120. 5:01different comparison operators one of
  121. 5:03the any sex
  122. 5:06or a term could be an attribute operator
  123. 5:09a constant
  124. 5:11so
  125. 5:12given that we can write any expression
  126. 5:17which is a predicate
  127. 5:19and applying that we can select
  128. 5:22the tuples from the relation r which
  129. 5:26satisfy this predicate
  130. 5:33so here we show a simple example
  131. 5:37instructor is a relation
  132. 5:40department name
  133. 5:41is an attribute
  134. 5:43within course physics is a constant or
  135. 5:46literal
  136. 5:47so this selection show
  137. 5:50will select all the tuples where the
  138. 5:53attribute department name is equal to
  139. 5:55physics and all the others will be
  140. 5:57eliminated
  141. 5:59for reference
  142. 6:00i have also
  143. 6:02quoted here
  144. 6:03the example that we had
  145. 6:05shown at the time of
  146. 6:07introducing relational algebra so you
  147. 6:10can see that here
  148. 6:11we have a more
  149. 6:13complex propositional term ah
  150. 6:16propositional formula where there are
  151. 6:18two terms
  152. 6:19the a should equal b
  153. 6:21and d should be greater than five
  154. 6:24so in the selection result both of these
  155. 6:28conditions must be satisfied by all the
  156. 6:30tuples which feature here
  157. 6:33so this is the first
  158. 6:35operation that relational algebra has
  159. 6:38the select operation
  160. 6:41next we move on to the second operation
  161. 6:43which is a project operation where
  162. 6:46a relation can be projected in terms of
  163. 6:50a number of attributes
  164. 6:52so pi is the notation
  165. 6:54r again is the relation and the
  166. 6:56subscripted a 1 a 2 a k
  167. 6:59are k attribute names k has to be at
  168. 7:02least one
  169. 7:03and these attributes will be retained in
  170. 7:07the relation
  171. 7:09so the result is defined as the relation
  172. 7:11of k columns
  173. 7:13by erasing all the columns of r which
  174. 7:17are not listed amongst this a to k
  175. 7:20naturally if you erase some columns it
  176. 7:23is possible that two rows
  177. 7:25that were distinct
  178. 7:27in those columns
  179. 7:29but are identical
  180. 7:32in a one to a k
  181. 7:35feature in the relation
  182. 7:37since every relation is a set
  183. 7:40no distinct
  184. 7:41no
  185. 7:43two copies of the same tuple are allowed
  186. 7:46so the duplicate rows will be removed
  187. 7:49from the result
  188. 7:51reminder this is in contrast to what sql
  189. 7:54does by default
  190. 7:56where duplicates or multi sets are
  191. 7:59allowed by default here we are talking
  192. 8:01about the formal relational algebra
  193. 8:04where it is purely set theoretic so
  194. 8:07duplicate rules on projection will be
  195. 8:10removed from the result
  196. 8:12so we have an example from the
  197. 8:14instructor relation we had seen earlier
  198. 8:16we are projecting id
  199. 8:18name and salary
  200. 8:20so we are removing the department name
  201. 8:23which also exists in the same relation
  202. 8:27and as a reference you can
  203. 8:30see
  204. 8:30the example that we had seen earlier
  205. 8:33while introducing
  206. 8:34the
  207. 8:35relational algebra where projection is
  208. 8:38done from three columns a b c
  209. 8:41into two columns a and c and this
  210. 8:43results in at least
  211. 8:45results in two rows which are identical
  212. 8:48and therefore
  213. 8:49in the final result
  214. 8:51one of those
  215. 8:52the duplicate one is removed
  216. 8:57moving on the third operation is
  217. 9:00quite simple it is set theoretic union
  218. 9:03so r union s where r and s are two
  219. 9:06relations are set of tuples which either
  220. 9:09belong to r
  221. 9:10or belongs to s or belongs to both
  222. 9:15the condition is you can take union if
  223. 9:17both these relations have the same arity
  224. 9:20and the order of the attributes must
  225. 9:24satisfy that
  226. 9:25every corresponding attribute
  227. 9:28must have compatible domains so if i
  228. 9:31talk about the second column of r
  229. 9:34and if we talk about the second column
  230. 9:36of s they must be of the same type and
  231. 9:40this must hold for all columns that the
  232. 9:43union
  233. 9:45forms that is all columns of r as well
  234. 9:48as s
  235. 9:49otherwise
  236. 9:50this operation is not defined
  237. 9:53so as an example we show that to find
  238. 9:56all courses taught in fall 2009
  239. 10:01semester this is a
  240. 10:04this is a query where we do a
  241. 10:08selection
  242. 10:10to find all tuples which are
  243. 10:12taught
  244. 10:13which represent
  245. 10:15courses taught in
  246. 10:17fall 2009 semester from the section
  247. 10:19relation
  248. 10:20we do a projection to get the ideas of
  249. 10:22those courses only
  250. 10:24and the second row
  251. 10:27tells you the courses that are taught in
  252. 10:30the spring 2010 semester
  253. 10:32and we do a union to get courses that
  254. 10:35are taught either in fall 2009 semester
  255. 10:38or in spring 2010 semester or both
  256. 10:43this is how the
  257. 10:48union is performed and this is the
  258. 10:51earlier example repeated here
  259. 10:55set difference is again just simple
  260. 10:58difference of sets
  261. 11:00r minus s where a tuple belongs to r and
  262. 11:04it does not belong to s
  263. 11:07so you remove all the tuples belonging
  264. 11:10to s that exist in r to get r minus s
  265. 11:13again they must have the compatibility
  266. 11:16of having the same arity and attribute
  267. 11:18corresponding attribute domains must be
  268. 11:20compatible
  269. 11:22this is an example to show to find all
  270. 11:25courses taught in fall two thousand nine
  271. 11:28but not in spring two thousand ten so
  272. 11:32as opposed to union in the last
  273. 11:34slide you do a set difference to get
  274. 11:37this result
  275. 11:38so this is how you can use set theoretic
  276. 11:40operation to
  277. 11:42get different relational results this is
  278. 11:46also the result from the earlier example
  279. 11:50set intersection
  280. 11:52can be supported
  281. 11:53is supported but it is not a basic
  282. 11:56operation
  283. 11:57because
  284. 11:58as it is defined by
  285. 12:00all tuples which belong to both r and s
  286. 12:03it can actually be computed by
  287. 12:06applying set difference twice
  288. 12:09and certainly for set intersection also
  289. 12:12the same
  290. 12:13assumption about arity and compatibility
  291. 12:15of types hold and this is the earlier
  292. 12:18example
  293. 12:21next is cartesian product where we take
  294. 12:23two relations
  295. 12:25and
  296. 12:27for the cartesian product we make
  297. 12:30we juxtapose one relation with the other
  298. 12:35so t is a relation from is a tuple from
  299. 12:38r
  300. 12:40q is a tuple from s and we put them side
  301. 12:43by side
  302. 12:44to get a
  303. 12:46t q
  304. 12:47row
  305. 12:48in the cartesian product r cross s
  306. 12:51which basically mean that you compute
  307. 12:55all possible combinations of tuples from
  308. 12:58r
  309. 12:59and of s
  310. 13:02it is assumed that the attributes of r
  311. 13:05and s are disjoint
  312. 13:07that is the schema of our intersection
  313. 13:10schema of s
  314. 13:11is null
  315. 13:13if the attributes are not disjoint then
  316. 13:16we must use renaming which will soon see
  317. 13:19and here is an example that we had shown
  318. 13:22earlier of r and s computing r crosses
  319. 13:27cartesian product is a very useful ah
  320. 13:30operation particularly for computing
  321. 13:32join as we have seen in sql already
  322. 13:37rename operation basically allows you to
  323. 13:39rename some expression attribute into
  324. 13:42another
  325. 13:43so the operator is row
  326. 13:46and you have an expression to which you
  327. 13:48give
  328. 13:49the
  329. 13:50name x
  330. 13:52and that is how the renaming of
  331. 13:54you can have multiple attributes of x as
  332. 13:57well
  333. 14:00division is a
  334. 14:01is another operator in relational
  335. 14:03algebra
  336. 14:05that ah can be applied between two
  337. 14:08relations but it is a derived operation
  338. 14:11so it says that
  339. 14:13if i have so let me just ah show you by
  340. 14:16by a little bit of
  341. 14:18sketch that if i have two relations
  342. 14:21which
  343. 14:22r
  344. 14:24which has a set of attributes z
  345. 14:27and s which is a set of attribute x such
  346. 14:30that
  347. 14:31actually
  348. 14:33the
  349. 14:34set z
  350. 14:36is
  351. 14:39a superset of x so z
  352. 14:42has more attribute the relation r has
  353. 14:44more attributes
  354. 14:45so
  355. 14:46if you take the difference of attributes
  356. 14:48between
  357. 14:50z and x and call it y
  358. 14:53then we are interested what happens on
  359. 14:56these remaining set of attributes y
  360. 15:01so this is what we have this is
  361. 15:04my
  362. 15:05x set of attributes this is where x
  363. 15:07occurs
  364. 15:08this difference is y this whole set is
  365. 15:11z
  366. 15:13now in this what we want is we want
  367. 15:17to
  368. 15:18in the output we want
  369. 15:20a relation having only the y attribute
  370. 15:23such that
  371. 15:25for every tuple in that relation
  372. 15:28if i consider all the tuples of s
  373. 15:32then their cos product must be a part of
  374. 15:36r
  375. 15:37so
  376. 15:38for every tuple here if there are
  377. 15:41say
  378. 15:42four tuples here a tuple here must have
  379. 15:46all these four tuples along with it in
  380. 15:49the result
  381. 15:50if it does not have any one or more of
  382. 15:52them then that tuple will not feature in
  383. 15:55the final result
  384. 15:59so the result of a division is a
  385. 16:01relation t y that include tuple t
  386. 16:04if tuples tr
  387. 16:06that is the part of the tuple
  388. 16:09the tuple that appear in r
  389. 16:13and
  390. 16:13on that on the y part the difference
  391. 16:16part
  392. 16:18it matches
  393. 16:19so that
  394. 16:21you have that t r x
  395. 16:24is equal to t s where t s actually exist
  396. 16:28in s this must happen for all tuples in
  397. 16:31s
  398. 16:33so division ah is a very good ah
  399. 16:36interesting operator which is often
  400. 16:39required for
  401. 16:40coding different queries
  402. 16:43so it is a derived operation let us take
  403. 16:45an example lets say this is
  404. 16:49this is the relation r
  405. 16:51and this is the relation s and i am
  406. 16:52trying to compute r divided by s so what
  407. 16:56i want is
  408. 16:58over the attributes of this is therefore
  409. 17:00x this is x
  410. 17:02this attribute y attribute set y
  411. 17:06so
  412. 17:07all
  413. 17:08over x all the values that i have
  414. 17:11i must have those values
  415. 17:14in the relation r
  416. 17:16if i do then the attribute
  417. 17:21the particular tuple
  418. 17:25matching on the attribute y goes on to
  419. 17:27the result
  420. 17:29so
  421. 17:30alpha goes on to the result because you
  422. 17:33have both alpha a
  423. 17:35alpha one as well as alpha two
  424. 17:39in the set r in the relation r
  425. 17:42beta one
  426. 17:45is there
  427. 17:46and beta two is also there
  428. 17:49so beta also goes into the relation
  429. 17:51alpha goes in because one is there
  430. 17:55two is also there
  431. 17:57but gamma will not go in
  432. 17:59because i have gamma 1
  433. 18:02but i do not have a tuple gamma 2 in r
  434. 18:06if i had gamma 2 in r that will go in
  435. 18:08the result
  436. 18:09so if i can
  437. 18:10say it again
  438. 18:12the whole of the relation s
  439. 18:16must happen
  440. 18:18over
  441. 18:19the x attributes of r
  442. 18:24consider these two together
  443. 18:27if that happens
  444. 18:28then
  445. 18:32the attributes
  446. 18:35on y
  447. 18:37the tuples would be chosen and that is
  448. 18:39how we get
  449. 18:41the result
  450. 18:42having alpha and beta
  451. 18:45let us look at one more example
  452. 18:49so this has got r has five attributes
  453. 18:51this has ah
  454. 18:53x has two
  455. 18:55so
  456. 18:56this is
  457. 18:59this is
  458. 19:00two attributes x these are three
  459. 19:02attributes y
  460. 19:04and what i have to look for is
  461. 19:08those tuples in r where
  462. 19:11the
  463. 19:15values over y would be same
  464. 19:18and i should be able to get
  465. 19:21the whole table of x
  466. 19:23over
  467. 19:24whole table of the relation s
  468. 19:27over the x attributes
  469. 19:28so if we look at here
  470. 19:31this is a one b one
  471. 19:34a one
  472. 19:35b one
  473. 19:37here
  474. 19:39these are identical
  475. 19:41so this particular tuple will
  476. 19:44go into the result
  477. 19:47if i
  478. 19:48look in here
  479. 19:53this tuple will go into the result
  480. 19:55but if i consider this tuple beta a
  481. 19:58gamma
  482. 19:59which has
  483. 20:01a one over d
  484. 20:04but beta a gamma
  485. 20:06does not have b one it has b three
  486. 20:10so it will not go into the result so if
  487. 20:13you conceptually look at that is the
  488. 20:15reason this is called a division so you
  489. 20:17get ah this here you get this here so
  490. 20:19this is like the way we divide that this
  491. 20:22is the hole and wherever it goes in
  492. 20:25if the tuples that are
  493. 20:28identical on the
  494. 20:29y set of attributes
  495. 20:32we will collect them into the final
  496. 20:34result
  497. 20:36so this is the division operation which
  498. 20:39ah by which we can compute the students
  499. 20:41who have taken both a and b courses
  500. 20:45with instructor 1 will be found out from
  501. 20:47this division operation
  502. 20:52so
  503. 20:52formally speaking a basic expression in
  504. 20:54relational algebra consists either of a
  505. 20:57relation in the database which is a
  506. 21:00instance or a constant relation which
  507. 21:04does not change which is given
  508. 21:06and
  509. 21:07then we have
  510. 21:08six
  511. 21:10operations of
  512. 21:12union set difference cross product
  513. 21:15selection projection and renaming that
  514. 21:18can give us all sorts of
  515. 21:20different relational algebra formula
  516. 21:23and also the derived operations and
  517. 21:25whatever we have seen of sql can be
  518. 21:28expressed in terms of this relational
  519. 21:31algebra formula
  520. 21:33now relational algebra is not something
  521. 21:36totally unique the same thing can be
  522. 21:38done in terms of other formulations also
  523. 21:41a second formulation which ah is also
  524. 21:44used is known as tuple relational
  525. 21:46calculus
  526. 21:47which is non procedural relational
  527. 21:49algebra was procedural because you are
  528. 21:51actually doing the ah explaining what
  529. 21:53the operations are you are detailing out
  530. 21:55what the operations are
  531. 21:57in tuple relational calculus
  532. 22:00you just specify
  533. 22:02what
  534. 22:03the
  535. 22:05condition is you are specifying what
  536. 22:07this condition is
  537. 22:09so those tuples which satisfy this
  538. 22:11condition form the relation
  539. 22:13so p is a predicate
  540. 22:16so whatever t
  541. 22:18satisfies the predicate are included
  542. 22:21and
  543. 22:22if a is an attribute then t a will
  544. 22:26denote the value of the tuple on
  545. 22:28attribute a a could be a single
  546. 22:30attribute it could be a set of
  547. 22:32attributes also
  548. 22:33and t is a relation that
  549. 22:37belongs to r
  550. 22:39p is as i said it is a its a predicate
  551. 22:42calculus formula so
  552. 22:44it could be a set of attributes or
  553. 22:46constants this i am just
  554. 22:48included
  555. 22:49for your help if in case you have
  556. 22:53ah become rusted with the predicate
  557. 22:55calculus you can refer to them a
  558. 22:56predicate calculus is a set of
  559. 22:58attributes and constants
  560. 23:00it has set of ah comparison operators
  561. 23:02the six of them
  562. 23:04there are a set of connectives these are
  563. 23:06all same as the propositional calculus
  564. 23:09ah there is implication which says if x
  565. 23:12is true then y is true
  566. 23:15if x is false then the whole thing is
  567. 23:16true
  568. 23:17vacuously
  569. 23:19and what makes it primarily pro
  570. 23:22predicate calculus is a fact that it has
  571. 23:24existential quantifier which says
  572. 23:28that
  573. 23:29the formula there exist t belongs to r
  574. 23:32q t
  575. 23:34holds if i can find at least one tuple t
  576. 23:36which satisfies q t
  577. 23:39similarly there is a universal
  578. 23:40quantifier
  579. 23:41where
  580. 23:42i will say that for all t belongs to r q
  581. 23:45t is true if
  582. 23:48for all tuples of r
  583. 23:50t satisfies q t
  584. 23:53so
  585. 23:54this
  586. 23:55in tuple relational calculus all
  587. 23:58conditions all predicates are formula of
  588. 24:01this kind
  589. 24:02and with that we can represent any
  590. 24:07relational set in full
  591. 24:10there is a word of caution because
  592. 24:13it is possible to write triple
  593. 24:15relational calculus expression
  594. 24:17that can potentially generate infinite
  595. 24:20relations now infinite relations are
  596. 24:23naturally not representable for example
  597. 24:25if i write simply this that r is a
  598. 24:28relation and i write this predicate that
  599. 24:31naught of t belongs to r which is
  600. 24:33basically complement set of r
  601. 24:35now a complement set of r
  602. 24:38potentially may be infinite if the
  603. 24:40domain is infinite
  604. 24:42so
  605. 24:43such
  606. 24:44expressions triple relational
  607. 24:47expressions are not acceptable as a part
  608. 24:49of the design
  609. 24:51so whenever we want to do this we would
  610. 24:54like to guard this
  611. 24:56by putting
  612. 24:57some additional condition
  613. 24:59and
  614. 25:00we have to make sure that any expression
  615. 25:03that we have in tuple relational
  616. 25:05calculus
  617. 25:06is a safe expression
  618. 25:08in the sense that it does
  619. 25:10give me finite number of
  620. 25:13tuples in the relation
  621. 25:17a third
  622. 25:18formalism that
  623. 25:20exist
  624. 25:22that is used is known as domain
  625. 25:23relational calculus
  626. 25:25which is also non procedural and
  627. 25:28equivalent in power to triple relational
  628. 25:30calculus again which is very similar to
  629. 25:33triple relational calculus the only
  630. 25:34difference being if you just recall
  631. 25:36tuple relational calculus we are writing
  632. 25:40ah collection of tuples t such that p t
  633. 25:44that is the predicate
  634. 25:46ah p is satisfied by t here instead of
  635. 25:50writing a tuple variable t
  636. 25:53we write expand it out in terms of all
  637. 25:56its components so we write the values of
  638. 25:59the different components of t over
  639. 26:02different n attributes and write it as a
  640. 26:05n tuple
  641. 26:07and so
  642. 26:08here instead of having one variable t we
  643. 26:11have n variable x one to x n and
  644. 26:13therefore the predicate is formed of
  645. 26:15this n variables where x one to x n at
  646. 26:19represent the different domain values
  647. 26:22domain variables
  648. 26:23and that leads to the reason for the
  649. 26:26name domain relational calculus
  650. 26:30now of the three formalisms that we have
  651. 26:32seen we will not go into ah direct
  652. 26:36mathematical proofs but in the next
  653. 26:38couple of slide i just show that
  654. 26:40they are equivalent in nature what means
  655. 26:43that if i can write an expression in
  656. 26:46relational algebra
  657. 26:48then it is possible to write an
  658. 26:49equivalent expression in triple
  659. 26:51relational calculus
  660. 26:53and in domain relational calculus and
  661. 26:55vice versa so if i can write an
  662. 26:58expression in any one of these
  663. 26:59formalisms
  664. 27:01then there are equivalent expressions in
  665. 27:03the other two formalisms as well which
  666. 27:06is probably very easy to see between
  667. 27:09tuple relational calculus and domain
  668. 27:11relational calculus because one is just
  669. 27:14representing the whole tuple as a single
  670. 27:16variable whereas the other is
  671. 27:18representing in terms of n domain
  672. 27:21variables so their equivalence is pretty
  673. 27:24much very similar except the fact that
  674. 27:27your
  675. 27:28predicate calculus formula has to change
  676. 27:32but it is not so obvious for
  677. 27:35the equivalence between relational
  678. 27:37algebra and the calculi so we just show
  679. 27:40a few
  680. 27:41examples of the basic operations for
  681. 27:43example say select operation
  682. 27:45so i am just not showing the proof i am
  683. 27:47just giving you some example cases to
  684. 27:50show so relation
  685. 27:51r has two attributes a b this is what
  686. 27:54you wanted to write in relational
  687. 27:55algebra that you want to collect all
  688. 27:57tuples where
  689. 27:59b is equal to seventeen naturally in
  690. 28:01triple relational calculus you can
  691. 28:03easily write the first condition is you
  692. 28:05are doing it on r so t must belong to r
  693. 28:08and your condition is b
  694. 28:10should be seventeen so this predicate
  695. 28:13will represent the same set
  696. 28:16or the same relation as in triple
  697. 28:18calculus
  698. 28:19in domain calculus there are two
  699. 28:21components a and b so you have to say
  700. 28:23component
  701. 28:24taken together must belong to r and the
  702. 28:27component b must be equal to seventeen
  703. 28:30so you can see that it is pretty
  704. 28:31straight forward to
  705. 28:33see the equivalence between a relational
  706. 28:36algebra expression involving select and
  707. 28:39the corresponding tuple calculus or
  708. 28:40domain calculus expressions
  709. 28:43this is a through an example but you can
  710. 28:45certainly easily generalize this as a
  711. 28:48proof
  712. 28:50similarly for projection if we do a
  713. 28:52projection on a
  714. 28:53then all that we are trying to do is we
  715. 28:56are trying to create
  716. 28:58a new relation where
  717. 29:00only
  718. 29:01the a attribute exist
  719. 29:04so in the tuple
  720. 29:06t the a attribute exist
  721. 29:09and if i
  722. 29:11have projected and got this tuple t
  723. 29:15then in my original relation r there
  724. 29:17must be some tuple
  725. 29:19p
  726. 29:20such that
  727. 29:22on the attribute a they match they are
  728. 29:24same
  729. 29:25so its the same thing in relational
  730. 29:27algebra we said that keep a and erase
  731. 29:29everything else here we are saying that
  732. 29:31if we have been able to get a tuple t
  733. 29:34which has a value t a
  734. 29:37then there must be a triple
  735. 29:39p in r
  736. 29:40which has the same value over the same
  737. 29:42attribute
  738. 29:43so this condition
  739. 29:45is
  740. 29:47equivalent representative of the
  741. 29:49projection
  742. 29:50and the same thing can be written in
  743. 29:52domain calculus you can
  744. 29:54go through it
  745. 29:56carefully and convince yourself
  746. 29:59you can combine these
  747. 30:01as in the relational algebra
  748. 30:03as well as in ah tuple calculus so here
  749. 30:06you apply one relation one operation and
  750. 30:08then the other one selection then
  751. 30:11projection
  752. 30:12here you can combining this this is part
  753. 30:14of projection this is also part of
  754. 30:17projection but this condition has come
  755. 30:19from the selection and get a total
  756. 30:21predicate calculus predicate which will
  757. 30:24give you the triple calculus expression
  758. 30:27for this combined expression of
  759. 30:29relational algebra domain calculus will
  760. 30:31certainly happen in a similar manner
  761. 30:35union certainly is straight forward so
  762. 30:37you can ah
  763. 30:39do it yourself
  764. 30:40set difference is again ah very straight
  765. 30:43forward because thats in fact in set
  766. 30:45theoretically whatever
  767. 30:47operations we have their
  768. 30:49relational algebraic definition itself
  769. 30:52is a tuple calculus formula you can
  770. 30:54expand them out and write in the domain
  771. 30:56calculus as well
  772. 30:58intersection plays out in the same way
  773. 31:00tuples that belong to both r and s
  774. 31:04cartesian product
  775. 31:06is little bit more involved because all
  776. 31:08that you are saying here is
  777. 31:10if i have a cartesian product then if
  778. 31:12that product has a
  779. 31:14tuple t
  780. 31:15then there must be a tuple p in the
  781. 31:18relation r the left relation there must
  782. 31:20be a tuple q in the in s the right
  783. 31:22relation
  784. 31:24so that the final tuple t matches p on
  785. 31:27the a attributes
  786. 31:30the b attributes that is attributes of
  787. 31:32relation r
  788. 31:34and
  789. 31:36the components of t matches
  790. 31:39the tuple q
  791. 31:41in the
  792. 31:42attributes of s if all these conditions
  793. 31:45happen together then naturally this
  794. 31:48tuple t
  795. 31:49is a
  796. 31:50valid tuple for the cartesian product so
  797. 31:52you could take examples and work this
  798. 31:54out and convince yourself that these are
  799. 31:57really equivalent
  800. 32:00we can ah define ah natural join in a
  801. 32:02similar way which i leave it as an
  802. 32:05exercise for you to convince yourself
  803. 32:08that this
  804. 32:10relational algebra expression for
  805. 32:11natural join indeed has similar
  806. 32:14equivalence in tuple and domain calculi
  807. 32:18division
  808. 32:19we just showed as a derived
  809. 32:22operation
  810. 32:23we have not showed how
  811. 32:26in relational algebra you can
  812. 32:28write division using the other
  813. 32:30operations i will leave that as an
  814. 32:32exercise as well
  815. 32:34but here what i show is in tuple
  816. 32:36calculus how you can write division
  817. 32:39ah using the quantifiers here you can
  818. 32:41see that here for the first time we do
  819. 32:43need to use the universal quantifier to
  820. 32:46make sure that while i divide that the
  821. 32:49whole of the table of s must be
  822. 32:51available against
  823. 32:52the
  824. 32:53part of the tuple part of the y
  825. 32:55attributes as we said that will be
  826. 32:57collected in the result
  827. 33:03so to summarize
  828. 33:05we have ah discussed
  829. 33:07primarily the relational algebra with
  830. 33:09some examples
  831. 33:11we have introduced the tuple relational
  832. 33:13and domain relational calculus
  833. 33:16and through a set of examples we have
  834. 33:18shown
  835. 33:19that we have illustrated that the
  836. 33:22algebra and the calculi are equivalent
  837. 33:25and
  838. 33:26i would
  839. 33:27request you to work out more examples to
  840. 33:30understand the equivalence or if you are
  841. 33:32really enthused please try out proving
  842. 33:36their equivalence formally as well
  843. 42:23you

About this transcript

This page contains the full transcript of Formal Relational Query Languages by Data Base Management System - IITKGP, generated from the public captions YouTube serves with the video. The transcript has 4,166 words across 843 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.