From Requirements to the Relational Model
Prerequisite Knowledge
This lecture builds on the following concepts from earlier lectures. If any feel unfamiliar, review the linked notes before proceeding.
Previously Covered in This Subject
- Entities, attributes, and entity sets — covered in Lecture 2 (Entity-Relationship Modeling)
- Keys: super key, candidate key, primary key, and foreign key — covered in Lecture 2 (Entity-Relationship Modeling)
- Relationships, cardinality ratios, participation, and weak entity sets — covered in Lecture 2 (Entity-Relationship Modeling)
- Schema and instances — covered in Lecture 1 (Introduction to Database Systems)
- Transactions and the ACID properties — covered in Lecture 1 (Introduction to Database Systems)
- Abstraction, multiple views, and multi-user sharing — covered in Lecture 1 (Introduction to Database Systems)
3.1 Course Journey and the Project
3.1.1 The Journey So Far
Before going deeper into today's topic, take a moment to recap the journey this course has taken so far and what it means for you.
The starting point was simple: in the database system world, there is a requirement to store data, fetch it across, and retrieve it. Doing that with traditional programming languages like Java or Python is a very tedious task. It demands a huge effort and a lot of programming structure from our side. To store and retrieve data in a concurrent manner, we wanted a proper scheme, a proper structure. That is why we say any database management application has four essential properties:
The four essential properties of a database management application
- Store the data — the data that defines the application itself must live somewhere, safely and permanently.
- Provide a proper abstraction — users and programmers work with a clean, simple view of the data, not with raw file bytes.
- Maintain proper views for different applications — each application sees only the slice of data it needs, in a shape it understands.
- Share and access the data concurrently — many users and many programs can read and update the same data at the same time without stepping on one another.
Keep this four-point list as a mental checklist. Every big database product you will meet — from Oracle to open-source systems like MySQL, to Microsoft SQL Server, and many, many more — is built to deliver exactly these four properties.
Real-world: this is exactly what the big database products provide. The range runs from Oracle to open sources like MySQL, and Microsoft SQL Server also has these features, along with many, many more options.
Why does any client want to create an application in the first place? In real life, a person may be solving the problem of one or two, or a limited number of, people. Going into the online world and creating an application — whether it is a desktop application, an online web application, an enterprise application, or a mobile application — lets that person reach at least an order of magnitude more people. And in every case, whenever an application is required, the people involved need to discuss and deal with data. This is also where the design process starts: the textbook design workflow runs through requirements analysis, conceptual design, logical design, schema refinement (normalization), physical design, and finally application and security design. Today's class covers the middle of that journey — turning a raw requirement into a conceptual picture (the ER diagram) and then into a logical design (the relational schema).
There is also a reality check for anyone who wants to become a data scientist. Many of us think data science means AI, machine learning, transfer learning, reinforcement learning, and so on — those are the keys. However, the major important component is dealing with the primary data: which data we can rely upon, which data we cannot rely upon, and how to get that particular data. In many organizations that is very important even when the three roles are not segregated. There is a data analytics person or a team that takes the data away and uses it.
Exam note: Data itself is often called the new oil: if we have the data, we can serve customers more humanly and give a better experience, rather than making an airline a commodity. The airline can become a wow experience for anyone, and then we can charge for an experience — and an experience means something more customized, more tailor-made, for an individual if not for a group. If you remember one idea from this section, remember that the database is the foundation that makes the analytics, the AI, and the customer experience possible.
3.1.2 The Project Assignment
One important component of today's session is the project. The assignment is this: take an airline company — for example, Tansai Airlines — or any airline company, or any banking application, or a supply chain application, and so on and so forth. Give a brief description of that application: who are the users, what are the benefits, and list the functions and features, and so on and so forth. You need to be aware of the project and keep working on it side by side, because the labs will expose you to it very, very soon.
The same requirement, in a similar learning form, will be shared in today's discussion — not exactly the same, but similar. From that requirement you can easily convert to an ER diagram, and then convert the ER diagram into a relational model as you progress. Keep in mind that the project expects you to do exactly these things.
Exam note: the assignment is marked and carries weightage. On feedback: with around a hundred assignments to check, some feedback may not appear along with the marks, but at least basic feedback is expected — and you can always reach out to arrange a one-to-one discussion of your assignment.
A milestone-based structure was floated for the project: starting today, submit the requirement specification by next week, the ER diagram within two weeks, and keep going from there. Submitting at each milestone helps, and feedback at each milestone would be nice — but the evaluation also has to respect the needs of every student in the class and keep everyone on the same level playing ground. That bare minimum is what the evaluation rests on. Students who want more — a new case, a new assignment, regular or detailed feedback — are welcome to ask for it.
3.1.3 Student Questions and Answers
Q: Which platform or tool do we have to create the ER diagram on?
A: No platform. Just use pen and paper — that is what is used. You do not need sophisticated tools; you need to understand what the ER model is. Use pen, use paper, draw an entity, write it specifically. That is more than fine. Is there anything in the ER diagram other than boxes, something written in the boxes, and rhombuses? That's it. You may use draw.io, you may use PowerPoint, or any other tool to draw boxes and write something that is easily available. We are not checking your drawing skills. If you understand the concept, that is all that matters. Don't go by the tools: first understand what you need to store, why you need to store, and how you need to store. Today you use pen and paper; tomorrow your organization goes across and says this will help increase the process — the tools are there to help you, no more than that.
Q: The requirement looks small, but when we represent it as an ER diagram it becomes bigger and does not fit on one paper. Can we split it portion by portion, put each portion on a different paper, and upload photographs of the ER product?
A: Customer requirement specifications are sometimes large, yes. I have not faced that requirement myself, but take a bigger paper — an A3 size paper also exists — and take a photograph and upload it. If you want to do extra effort, use one of the tools to draw the boxes and write in them. If you go by the tools you will miss the basic heart of it, which is the process. Tools are there only to help you represent it. Customers in industry use whatever they use; you will use it anyway. If you understand the process — the user requirement comes, it is stored to give clarity to the user, it is stored in some form of schema, we store and we retrieve — the page is not a requirement or a limitation. The requirement may come in text format; the user may give it in another format, that is okay. Tomorrow your organization may use Cassandra or MongoDB or Neo4j or any other NoSQL — that is okay too. If you understand the process and the fundamentals, and one of the techniques to use them, you are fast enough to learn anything that goes on in the organization.
Q: Is it okay to use online resources to complete the project and other assignments — specifically AI tools like Google, GPT, and so on? Not for the diagram purpose, but generally for any assignment where we just need to write something.
A: You are putting me on the wrong foot here. I discourage plagiarism — everyone discourages plagiarism, including AI-generated plagiarism. Secondly, you can use online resources wisely; I am not discouraging that. You can use books, you can learn from different resources — hopefully they will be correct, but you need to verify. If you want to learn from an AI tool as well, I really want to teach you how to use AI tools. Even in generative AI tools, you have to ask good questions to learn properly. If you use them to learn properly and use your own brain cells to apply properly, nobody will be happier than me. But if you want to offload it and say "this will do it for you," I refrain. Try it and you will ultimately find out they become your hands and legs to do it again — but your eyes will be there. The brain should be yours; you need to tell it what to ask. If you give it across, either the information might not be correct, or, whatever is correct, it might not add value to you. My responsibility is not only that you learn properly, but that you become so valuable that you can give value to others. Generative AI tools should make your task easier, not supplement the learning process. Go ahead and use them, but ensure the words are coming from you and you use them for learning. Feel free to learn from any source you prefer — learn it, apply it, become secure.
Q: Do we get feedback or just evaluation for this assignment?
A: Of course it is marked — it has weightage. You are asking whether you get feedback on how you can improve, or only a mark like 10, 12, or 15. I definitely want to see all the assignments individually and give feedback on how you can improve; I will have to check my schedule on how I can apply it. Generally you will see at least some basic feedback — "this place will require improvement," "this place is a good one." If you don't get it along with the marks, because there are 100 to 100 assignments to check, you can definitely reach me, mail me, ask for my time, and have a one-to-one discussion on your assignment.
Q: When designing complex database systems, how do we consider integrity and ensuring less redundancy — like normalization and other things — while designing the ER diagram?
A: We don't have to consider those while designing the ER diagram. All these concepts will come later — very, very soon from today's class onwards and the next class onwards. Whenever the user gives a requirement, your only requirement is to understand it, understand what the user is saying, ask powerful questions — even if the user is not specifying — store it across, and create the ER diagram: some representation where the user says everything has been told and captured properly. All the constraints, all the requirements, all the relations — everything captured. Even something that cannot be represented in the ER diagram is separately noted: "these are some constraints, some integrity constraints that are there." Then you convert into a relational schema. From the relational schema you write the functional dependencies and convert them into normalizations — first normal, second normal, third normal, whatever BCNF. That is how the process goes.
Q: So whatever requirement the user has will be listed in the ER diagram at that point of time?
A: Correct. If there is any redundancy or other issue, that will be considered later, in the database stage.
Q: The project handout lays the tasks out milestone-wise. What is the expectation — do we submit the final version, or do we submit as we make progress at each milestone: capturing requirements, converting into an ER diagram, normalization, validation?
A: What is best for you? Let me give my perspective too — you can ask me what is best for me as well. One way: it starts today. By next week you submit the requirement specification; within two weeks you submit the ER diagram; the next two weeks you do the next step. Will that be comfortable? Submitting at each milestone helps, and feedback at each milestone would be nice. See, it is not just you — you may be the super regular student, but I have to take care of all the other hundred students in the class as well, who have their own requirements. I need to respect them and ensure all of them are on the same level playing ground — at least the bare minimum on which I evaluate. Somebody who wants to pull something more out of me — a new job, a new case, a new assignment, regular or detailed feedback — I am all there for you.
Q: Are we supposed to use SQLite only, or will any other SQL software be okay?
A: Mostly all of them are the same. Even if you use any other open-source one — SQLite and others — no issues. Go ahead.
Recap + bridge: The database journey has four essential properties (store, abstract, view, share) and every application starts with a user requirement. That requirement is the raw material for the rest of the course: it becomes an ER diagram, then a relational schema. Next, we watch a real requirement arrive — the Lufthansa Airlines example — and see how the designer turns a client's words into a picture the client can confirm.
3.2 Customer Requirement Specification
3.2.1 The Lufthansa Airlines Example
Hook: A user walks into your office and starts talking about geopolitics, demographics, the World Cup, and airline ticket prices. Your job? Turn that conversation into a database design. How do you even start?
A requirement specification may come to you while you are wearing the hat of a database administrator or a designer. The user may start speaking about the problem he or she is solving. Say the user flies Lufthansa Airlines planes and is the owner of that airline. The user says: now we want to create a system where we get to know, in which part of the world the geographical geopolitics is playing out, what are the demographic trends that are happening. We want to store all the data — this is a place where the World Cup is going to happen, this is a place where Olympics are happening, this is a place where elections are going to happen, these are the demographic changes happening in that particular territory, and so on and so forth. All of them impact and affect the pricing we have as an international airline — how much price we can quote. And this needs to be planned way ahead, at least a year ahead. If something needs to be done — like the Qatar football World Cup was happening — we may have more flights diverted to that place during that time.
Worked mini-example: reading a requirement for its data
The Lufthansa monologue, translated into what a database designer hears:
- What data must be stored? World events (World Cup, Olympics, elections) with location and timing; demographic trends by territory; flight routes and prices; historical demand.
- Who is it for? The airline's pricing and planning team, plus a data analytics team that consumes the data later.
- What is the key business rule? Pricing decisions are planned at least a year ahead; big events mean more flights diverted to that region.
- What will the system do? Store the events, let planners query them, and let analytics pull the data away.
Notice: at this stage we are not drawing boxes. We are capturing what the user said, asking questions, and writing it all down. The box-and-rhombus picture comes after.
Very good, very good problem — it can nicely be done. The basic idea is that somebody needs a place to store the data, somebody needs to access the data, and then a data analytics person or team takes the data away. The requirement for the user starts from exactly what you just heard. Then the design team starts asking the client: okay, I understand that, but what are the different components in that particular application? Who are the players you will be solving for? What are their roles? And so on and so forth. The customer requirement specification you use to create the ER diagram — the diagram we saw in the last class — and that diagram will be used to convert into a relational schema.
Real-world: this is dynamic pricing in the airline industry, driven by geopolitics and demographics. It is exactly the kind of problem where the database designer turns ten, twenty, thirty, forty pages of requirement into a picture the client can confirm.
3.2.2 The University Schema and Pertinent Questions
The university structure we worked with in the last class shows how a first-level cut looks. The user comes to you and says: yes, we have a department, we have an instructor, we have students, and students have these things. We need to store courses, sections, some other information, classroom, and enrollment — these things. That is the first-level cut the user gives you. Now it is your responsibility to keep asking pertinent questions to get more about the user's requirement.
Scope: The first-level cut is never the whole design. It is the starting point for an interview. The design process officially runs through six steps — requirements analysis, conceptual design (ER), logical design (relational schema), schema refinement (normalization), physical design (indexes, storage), and application and security design. The questions you ask today serve the first three steps; the later steps consume your relational schema, not the client's rambling. And keep the professor's rule from the Q&A in 3.1: normalization and redundancy are decided later, in the database stage — not while drawing the ER diagram.
What kind of questions work? If you ask "what are the constraints between a section and a department?", the user might go blank — "what do you mean by requirement? what do you mean by constraints?" That question is difficult at first. A better question is: how are students and instructors related? The client can start describing that. Why do you ask? So that you can capture and understand the requirements — later you can create the ER diagram, a place where you can store and retrieve the information whenever required.
| Question to ask the client | Why it works |
|---|---|
| "How are students and instructors related?" | Plain words; the client can narrate the situation without database vocabulary |
| "How are the prerequisites of a course managed? Do courses have multiple prerequisites?" | Straightforward; the answer settles one-to-one, one-to-many, many-to-many, and total participation for the prereq relationship |
| "Can multiple instructors teach a section? Is it limited to one?" | Straightforward; the answer settles the teaches cardinality |
| "What are the constraints between a section and a department?" | Hard at first — the client does not speak the words "requirement" and "constraints" fluently; ask this only after building the conversation |
Some better questions: how are the prerequisites of a course managed? Do courses have multiple prerequisites? That is a straightforward question, and answering it uses our one-to-one, one-to-many, total participation ideas. Can multiple instructors teach a section? Is it limited to one? Can one instructor teach one? After all these questions you will know whether this requirement is many-to-many, many-to-one, or one-to-one, and you will use exactly the same thing to create an ER diagram, something similar to what you have already seen in previous classes. Because your requirements are clear — you have seen the requirements from the user — you can draw the diagram, show it to the client, and say: is there anything more or less that I need to verify? The client says yes, this is okay. Then you use that information to convert into a relational schema, which you will use to store and retrieve the information.
Remember the purpose of the ER diagram: all those ten, twenty, thirty, forty pages — or four pages — of requirement you specified are encapsulated into one picture so that everything — the constraints and the requirements — is clear. Then the diagram is used to create a relational schema, wherein we will use insert, update, create — those queries — to store and retrieve the information. Whatever SQL experience you have comes at the later stage; till then, the client wants to create an application, we are leading the database team in our organization, and we are responsible for creating the structure where the data will go and the structure of how the data will be retrieved in a possibly concurrent manner.
3.2.3 The Room Analogy
Intuition + analogy (the professor's room): Take it as if you are creating your own room, or a house you will be having. There is a place — a cupboard or a wardrobe — where my clothes will go. There is a place where my books will go. There is a place where the utensils will go. There is a place where the keys will go. There is a place where the toys of the kids will go. There is a place where the beds and other furniture will go. A place where the television is there. A place for anything new that comes across with respect to daily or monthly chores — like the consumables you use for cooking: where will they go?
The mapping is one-to-one with database design: each kind of thing gets a fixed home. So that when you know there is a place where I store my books, a place where I store the vegetables and other stuff, a place where I store the keys — later on, when there is an examination of database systems and you have studied it, it is not like a lump of everything where you have to hunt. You know that place: there is my database systems book, and I can find it across. More so, if you have a place to store the keys and you know the keys are stored there only, it becomes very difficult for you to misplace the keys. In a very simple manner, you can relate exactly the same thing to data: you will be creating a place to store the data wherever it comes, and you will know where to fetch that data across.
Where the analogy breaks: a house has one owner and one family, but a database is shared — many users store and retrieve at the same time (property 4 from 3.1). The truer picture is a shared warehouse with a catalog: each item still has a fixed shelf, but many workers walk the aisles concurrently and the catalog (the schema) tells them exactly which shelf to visit.
3.2.4 The End-to-End Process
The whole process, in one line: the user gives the requirement; the requirements need to be converted in such a way that we understand all of them; we convert them into a relational schema, wherein we will store and retrieve everything. So the process of converting to an ER diagram and then converting to a relational schema is equally important as storing and retrieving through SQL.
Pitfalls in requirement capture
- Jumping straight to boxes — the moment the user says "department, instructor, student," some designers start drawing. The requirement is not captured yet; the first-level cut is only the beginning of the interview.
- Using database vocabulary too early — "what constraints exist between a section and a department?" stops the conversation cold. Ask questions the client can answer in plain language.
- Accepting the requirement on one page forever — requirements are large; today's talk, tomorrow's email, and the meeting notes all carry pieces of the same picture. Every piece belongs in the specification.
- Treating tools as the model — draw.io, PowerPoint, and MindMap only draw the picture; they do not replace understanding what to store, why to store, and how to store.
Recap + bridge: The requirement specification is the seed of the entire course: requirement → ER diagram → relational schema → SQL. The professor's room analogy gives you the intuition (a fixed place for everything), and the pertinent-questions technique gives you the method (plain-language questions that reveal cardinalities and participation). In the next section we revisit the ER diagram itself — entities, relationships, weak entities — so the conversion rules have solid ground to stand on.
3.3 ER Model Recap: Entities, Relationships, Weak Entities
3.3.1 Entities, Attributes and Relationships
Hook: You have a user requirement in front of you. How do you turn a paragraph of client talk into a picture that the client — who has never seen a database — can confirm with a nod? The ER model is that picture language.
From the last class we discussed what an entity is and what a relationship is. There is a place where the user requirement is specified, from which you have converted into entities. An entity has a name; it has its own attributes. There is a relationship, and there is one-to-many or many-to-one with total participation. Wherein we have a weak entity as well.
Formalize: the vocabulary of the ER model
- An entity (a thing in the real world with an independent existence) is the basic object the ER model represents — a physical object like a person or a car, or a conceptual one like a company, a job, or a university course.
- An entity type (the schema of a kind of entity) is defined by its name and its attributes — for example, the entity type STUDENT has attributes ID, name, and total credits.
- An entity set (the collection of entities of a type at one point in time) is usually called by the same name as the type. The professor pictures it as a bag: open the bag labelled STUDENT and every entity of that type is inside.
- An attribute (a property of an entity) is a "particular property that describes it." Attributes come in kinds worth knowing: simple or atomic (not divisible), composite (divisible, e.g., address into street, city, state), multivalued (several values allowed, e.g., phone numbers), and derived (computed from others, e.g., age from birth date).
- A relationship type among entity types defines a set of associations — a relationship set — among entities of those types. Each relationship instance is an association that includes exactly one entity from each participating entity type. The number of participating entity types is the degree: degree two is binary, degree three is ternary.
The entity-relationship model is exactly what its name says: entities and relationships. In the diagram, the rectangles hold entities, and the rhombuses represent relationships — a relationship is never an entity, it is always a relationship, connected to one, two, or more entities. You may also think of encapsulating several entities and relationships into a single relationship that has its own attributes, so that the relationship carries proper attributes and they are defined properly.
Scope: One notation trap first. Textbooks draw cardinality in two different dialects: the Elmasri style prints a "1", "M", or "N" on each edge of the diamond, while the Silberschatz style uses an arrow to mean "at most one" (the arrow points at the one side) and a plain line to mean "many." This course reads the arrow style: pointed arrow means one, no arrow means many. When you open a different book, first check which dialect it speaks, or you will misread every diagram.
3.3.2 Weak Entities and the Identifying Relationship
Formalize: weak entity, owner entity, identifying relationship
A weak entity means this: when we are storing it as an entity itself, all of its own attributes are not enough to uniquely distinguish between all the entities in that particular set. Formally, an entity type that has no key attributes of its own is a weak entity type; one that does have a key is a strong (regular) entity type.
Consider section as a bag in which we have filled the elements of individual section entities. Each section entity has a section ID, a semester, and a year. Now, two section entities in that bag — if you only consider them with section ID, semester, and year — you might not be able to distinguish them: they can look the same. So when we identify the section entity with a course ID, we specify that right now they are not unique by themselves, but this entity has a relationship with some other entity, the course, and that relationship makes it complete in itself.
- The entity type that completes the weak entity is the owner (or identifying) entity type — for section, the owner is course.
- The relationship between them is the identifying relationship — for section, that is the sec_course relationship.
- The weak entity's own identifying attributes (section ID, semester, year) form its partial key or discriminator — they distinguish weak entities only among those related to the same owner.
- The full key of a weak entity is always: owner's key + partial key. For section that is (course ID, section ID, semester, year).
Because when we store them in the relational schema, they will be stored in such a way that all of them are unique and solve the purpose of the relational model, which says it is a set and all the elements of the set are unique. So we capture that properly. At the same time, we meet the client's requirement: these two seemingly equal entities are made different by their relationships with the owner entity.
The relationship from a weak entity to its owner entity — also called the identifying entity — is drawn as a double rhombus. Whenever a relationship connects a weak entity to its owner entity, it is a double rhombus; other relationships with a weak entity are not double rhombuses. In the university schema, the owner entity of section is only one — the course. That is why the double rhombus is on that one side. Its owner entity defines its key: course ID, section ID, semester, and year. Section has only one owner entity; everything else section is associated with takes part as a normal entity. This is the way we read it across.
Pitfalls
- "A weak entity has no key at all" — wrong. It has no key by itself; together with its owner's key it is perfectly identifiable. A weak entity also always has total participation in its identifying relationship: a weak entity cannot exist without an owner (this is existence dependency). But be careful: not every existence dependency makes a weak entity — a driving license depends on a person, yet it has its own key, so it is strong.
- Double rhombus everywhere — the double rhombus belongs only on the identifying relationship of a weak entity. Other relationships in which the weak entity participates are normal (single) rhombuses.
- Forgetting the notation for the weak entity itself — the weak entity is drawn as a double rectangle, and its partial key is underlined with a dashed line.
3.3.3 Reading Cardinality and Participation
There are arrows in some places and no arrows in others. A pointed arrow means one; without the arrow means many. The double line means total participation. For example: a student can be advised by at most one instructor, and an instructor can advise many students — this is many-to-one. When a student and a department are related: a student can be related to at most one department; a department can have many students. However, all students in the student entity set must be related to some department — that is total participation. Look at the bag of student entities and the other bag of department entities: every entity in the student bag must be related to some department. So the double line says the participation is total, and the arrow says the student can be related to at most one department.
Worked example: reading the university diagram
Draw the picture in your head (or on paper) — rectangles STUDENT, DEPARTMENT, INSTRUCTOR, COURSE, SECTION; diamonds advisor, sec_course, takes, teaches.
- advisor between STUDENT and INSTRUCTOR: arrow on the STUDENT side (a student has at most one advisor), no arrow on the INSTRUCTOR side (an instructor advises many students). Reading: many-to-one, from many students to one instructor.
- stud_dept between STUDENT and DEPARTMENT: arrow on the STUDENT side plus a double line on the STUDENT side. Reading: a student relates to at most one department (arrow), and every student must relate to some department (double line = total participation). A department, by contrast, may have zero or many students — no arrow, single line.
- sec_course between SECTION (weak, double rectangle) and COURSE: double rhombus for the relationship. Reading: section is weak, course is its owner, and the identifying relationship makes each section complete.
Visual landmark to remember: the double line and the arrow describe two different things — the double line answers "must every entity participate?" (participation, the minimum), while the arrow answers "how many can one entity participate in?" (cardinality, the maximum).
3.3.4 Student Questions and Answers
Q: In the ER diagram, the rhombus which shows the relationship — is it also an entity?
A: No, it is a relationship. It is an ER diagram in which this is a relationship — the rhombus is a relationship; this is an entity, that is a relationship. That is how we define it: entity-relationship model, entity and relationship. And if you look at the double rhombus — the double line inside it — it tells that this relationship is related to a weak entity: whenever a relationship connects a weak entity to its owner entity, that is a double rhombus. Other relationships with a weak entity are not double rhombuses. That double rhombus tells us this is the relationship from a weak entity to its owner, its identifying entity — that is why it is double.
Q: Some lines have single arrows, some have double arrows, and some have double lines. What do they mean?
A: The point of the arrow means one; without the arrow means many; and the double line means total participation. For example, this is a many-to-one relationship: a student can be advised by at most one instructor, and an instructor can advise many students. With a double line, all students in the student entity set must be related to some department.
Q: Is the tool MindMap used for the ER model, or is it a different way of creating a structure?
A: MindMap has nothing to do with this. I just used it to share and explain things — that's it. Someday I use a PowerPoint presentation, and PowerPoint has less to do with database systems, isn't it? It is just one of the tools to teach. The only thing you need to be worried about is the diagram itself — what are the details of this diagram. That's it.
Recap + bridge: The ER model has exactly two constructs — entities (rectangles) and relationships (rhombuses) — plus three decorations that carry the constraint detail: arrows (at most one), double lines (total participation), and the double rectangle/double rhombus pair for weak entities and their identifying relationships. One more subtlety from the textbooks before we move on: in the ER world there is no "primary key" concept — the diagram underlines key attributes, and the primary key is chosen later, during the mapping to the relational schema. That choice is exactly the topic of the next section.
3.4 Keys: Super Key, Key, Candidate Key, Primary Key
3.4.1 The Four Key Concepts
Hook: In the ER diagram some attributes are underlined — but those underlines belong to the relational world, where four different ideas hide behind the single word "key." Get these four straight and the rest of the course gets easier.
The keys we see underlined in the ER diagram belong to the relational schema world. There are four concepts to keep straight: super key, key, candidate key, and primary key.
Formalize: the four key concepts
Let a relation have attribute set . Any subset whose combination of values is unique across the records of the relation is a super key — no two distinct records may agree on all attributes of . Note: a super key may contain extra (redundant) attributes. Every relation has at least one default super key: the set of all its attributes, because a relation never holds two identical records.
A key is a minimal super key: no attribute can be dropped from it without losing uniqueness. Formally, if is a key, then for every attribute , the set is not a super key anymore.
When there is more than one minimal set, each of them is a candidate key — the word "candidate" signals that any of them could be the key. The user, or the administrator, then designates one candidate key as the primary key of the relation — the one whose values are used to identify tuples, the one the DBMS indexes and expects. Other candidate keys remain as unique keys (secondary keys).
The relationship between the four, in one line: a super key is any unique set; a key is a minimal super key; every key is a candidate key; and the chosen candidate key is the primary key.
Worked example: the section relation with six attributes
Let's say in the section relation we have six attributes — course ID, section ID, semester, year, building, and one more — and we say that course ID, section ID, semester, and year form a key. That means all the records in that relation, when these four attributes are combined together, their combination is unique.
- The set {course ID, section ID, semester, year, building} is a super key: it is unique — of course it is, it contains the key — but the building attribute is redundant for uniqueness.
- The set {course ID, section ID, semester, year} is a key: drop any one of the four, say semester, and two records with the same course, same section ID, same year (different semesters) can collide.
- If some other minimal combination — say a five-attribute set — also happens to be unique, then there are two candidate keys, and the administrator picks one as the primary key.
Sense-check: adding attributes can only make a set more unique, never less — so every key is a super key, but most super keys are not keys.
Another everyday example, from the reference book: the CAR relation has two candidate keys — License_number and Engine_serial_number. Either one identifies a car; the designer underlines one of them as the primary key and keeps the other as a unique key. Notice the two keys have the same size here, but that is not required: a key is minimal, not "smallest" — one relation can have a one-attribute key and a three-attribute key at the same time.
The intuition, as the discussion emphasized: do not cram these definitions. Understand the relationship between them — the more you understand why, the more heartily and correctly you will do it every time. Think of the chain as containment: primary key is one of the candidate keys; candidate keys are exactly the minimal super keys; super keys are all unique combinations. Once you see the containment, you never need to memorize a single definition.
3.4.2 Foreign Key at a Glance
A foreign key is a different concept from the super key, and it will come up again in detail later. For example, in the advisor relation there is a student ID. The student ID refers to the attribute ID in the student relation. That is a foreign key referring to the ID attribute in the student relation. Why do we do that? Because if the student does not exist, this record should not exist as well — that is why we refer through a foreign key.
Pitfalls
- Adding a redundant attribute to a key — {course ID, section ID, semester, year, building} is unique, but it is not a key; it is a super key. The minimal set is the key.
- Thinking the primary key must be the smallest key — minimality is about dropping, not about size. A four-attribute key and a two-attribute key can be candidate keys of the same relation.
- Confusing foreign key with super key — a foreign key is about referencing another relation's key (the student ID inside advisor points at the student relation). It is not about uniqueness at all. They live in different worlds and we keep the words separate.
- Believing the primary key is chosen in the ER diagram — the ER diagram underlines key attributes; the primary key is designated during the mapping to the relational schema.
3.4.3 Student Questions and Answers
Q: In the section entity, the keys are underlined — two keys are underlined. Can I consider that those two underlined keys belong to the primary key?
A: Let me get the clarity once again. There are four concepts: super key, key, candidate key, and primary key — all of them are related to the relational schema, which is also a topic for today's class. Here, the only thing is something which is uniquely distinguishing. When we talk about a super key, we mean: when we are storing the records, this set of attributes distinguishes the different records — that is a super key. However, the minimal one is called a key. In the section relation we have six attributes, and we say course ID, section ID, semester, and year form a key — their combination is unique. Now, the minimal one is called a key. And if there are more than one of them — these four or five also form a key — then each individually is a candidate key. The user or the administrator may take one of them as the primary key for this particular relation. That is the relationship between super key, key, candidate key, and primary key.
Q: Are you considering the super key as the same as the foreign key, because in the recorded material they are connected?
A: Foreign key is a different one. Let's suppose this is a student ID. The student ID in the advisor relation refers to the attribute ID in the student relation. That is a foreign key referring to the attribute ID in the student relation. Why do we do that? Because if the student does not exist, this should not exist as well. That is why we refer through a foreign key. We will discuss it more in today's class.
Recap + bridge: Super key = unique combination; key = minimal super key; candidate key = one of possibly several keys; primary key = the designated candidate key. The foreign key is a separate idea — a reference to another relation's key — which we meet again in full detail when we convert relationships into relations (3.6) and again under the relational constraints (3.9). Next, the extended ER model: what happens when three entities want to relate at once.
3.5 The Extended ER Model: Ternary Relationships
3.5.1 Ternary Relationships
Hook: Two entities can relate easily — student and instructor, student and course. But what do you do when a fact makes sense only when three entities are locked together? The extended ER model has an answer, and also a warning.
A topic that was asked about today is the ternary relationship and things like that. Let's first talk about the extended entity-relationship model. It might not be directly used, but there can be relationships of higher degree, like the ternary model. Suppose you have a project, an instructor, and a student. You are a student and I am an instructor, and you are working on a project — that project can be anything. Hypothetically assuming the project is a very, very valuable one — it may turn out to be the one that leads to a research publication, or to commercialization, or a conference publication, or a patent. In that case, the student, the instructor, and the project are related. They automatically have some relation which cannot be further bisected into two: the student has its own entity, the project has its own entity, the instructor has its own entity. Even though we wanted to make it a binary one, the relationship is such that it has to be the project-guide relation. We cannot have it as two-one.
Formalize: degree and the ternary relationship
The degree of a relationship type is the number of entity types participating: degree two is binary, degree three is ternary, degree is n-ary. A relationship set of degree is a subset of the Cartesian product of the entity sets:
For the research example, with = students, = instructors, = projects, the relationship set is
Each relationship instance is an association of exactly one entity from each type — it is not a pair of binary facts. Why does that matter? The classic textbook example is SUPPLY: a supplier supplies part to project . If you split it into three binary relationships — "s supplies p," "p is used by j," "s works with j" — you can have the three pairs hold separately without the real-world triple being true. The ternary fact "s supplies p to j" carries meaning the three pairs cannot reproduce. That is the reason a relationship can be irreducible to binary ones.
Similarly, there is another relation for evaluation — when we want to have what grade you get, that is also a relation, and how do you evaluate for it? Even though we want to make it only binary, sometimes we cannot avoid it. So there will be instances where more than two entities participate in a relationship. It is not that it is not allowed — but generally we try to have two. It is uncommon, but you may also encounter three, and sometimes three entities participating with a fourth one. For example, if evaluation is an entity, it interacts with all three — student, instructor, project — and creates a relationship. You may also encapsulate it as a single one and say this is one relationship. If we get funding, we have a funding agency related to that relation; if we have evaluation, we have something related to that. You may do it as a great one, just to ensure that the relationship has proper attributes and they are defined properly.
3.5.2 Degree versus Cardinality
There are two things to keep separate here: degree and cardinality. The degree is whether the relationship is binary, ternary, and so on — how many entities participate. Cardinality is whether the relationship is one-to-one, one-to-many, many-to-one, and so on. Now the question: when there is a ternary relationship, can we specify cardinality? You will find that even if there is one arrow, you may say many of them are participating, but generally it is two-way. How complex it goes — even to speak about it you can appreciate how difficult it is in real life. That is why we avoid more than two participants.
Worked example: where do the arrows go?
Suppose a project and a guide are related. Hypothetically, I put a constraint that there is one student. Now where do the arrows go? The student is one — but do I put an arrow here or do I put an arrow there? That is very, very difficult to put. So we say the student needs to participate only once per instructor per project — I put two arrows. But does that mean the instructor can also take only one student in one project? That goes across in a very different tangent.
- Till the time everything is many-to-many — many students, many projects — there is no issue.
- As soon as a "one" comes across, ambiguity comes in: "at most one student per (instructor, project)" is not the same as "at most one instructor per (student, project)" — and a diagram with arrows on two sides can be read either way.
The textbook rule for n-ary keys uses the 1/M/N notation instead of arrows: if a "1" is printed on a participant's arc, that participant is not part of the relationship's key (the combination of the other participants already determines it). If all participants are M or N, the key is the combination of all of them. This is why we say that although a cardinality can be specified for a ternary, it loses its charm and the detailing when we go to ternary — even reading what the person has specified becomes an exercise in careful interpretation.
3.5.3 When to Use the Extended Model
Can the relationship be more than ternary? Of course, of course — if required, you can have it. Try to make it two; if not, three. But that makes it very complicated, and generally we do not experience it in normal life. As for whether the extended model comes after the original ER model was developed: no, it is simultaneous. Whenever it is required, you can form it. There are some other bags in your armour that you can use to shoot — you get some different arsenal whenever it is required. It is the same thing, the same concept: whenever you require it, use it; when you don't require it, don't use it. Don't try to overcomplicate it.
Pitfalls
- Forcing a ternary into binary relationships — splitting "instructor guides student on project" into three pairs loses the triple constraint; the pairs can all exist without the triple being true.
- Reading arrows in a non-binary relationship — a diagram with two or more arrows out of a non-binary relationship can be interpreted in two different ways; the standard rule permits at most one arrow out of a non-binary relationship.
- Specifying a "1" without deciding what it constrains — "one student" needs the anchor "per instructor per project," otherwise the diagram is ambiguous.
- Using the extended model for every small problem — the arsenal exists for the cases that need it; overcomplicating a simple schema is a design mistake, not a virtue.
3.5.4 Categories and Union Types
The extended ER model has a second construct beyond the ternary relationship: the category, also called a union type. A category is a subclass that has multiple superclasses, where the superclasses represent different entity types. This is the precise distinction that students mix up: in specialization, the subclasses all inherit from one superclass (SECRETARY and ENGINEER are subclasses of the single superclass EMPLOYEE); in a category, the members are drawn from several unrelated entity types, and the category represents their union.
Formalize: category as a union
Formally, a category is a subset of the union of defining superclasses (), where the superclasses are different entity types:
Read this against the professor's vocabulary: specialization answers partition ("one kind of thing, divided into kinds" — an employee that is a secretary or an engineer), while a category answers union ("any one of these different kinds of things"). There is also a third shape to keep distinct: a shared subclass such as ENGINEERING_MANAGER must belong to all its superclasses at once — it is a subset of the intersection, whereas a category member belongs to exactly one of its superclasses.
The notation. The superclasses are connected by lines to a small circle containing the union symbol (), and an arc carrying the subset symbol connects the circle to the category. A total category — every instance of every member superclass belongs to the category — is drawn with a double line between the circle and the category; a partial category uses a single line.
The standard example. Consider the requirement: "a person, a bank, or a company can be the owner of a vehicle." The three superclasses are PERSON, BANK, and COMPANY — three completely different entity types with different keys (SSN, bank code, registration number) and different attributes. Yet the designer needs a single owner concept that can be any one of them, because a VEHICLE record must reference "its owner" without knowing which kind of owner it is. The category OWNER is exactly that: it is not a new independent entity type, but the union of the three. In the example, only some companies own vehicles, so OWNER is partial: a given bank may or may not own a vehicle, but every vehicle owner must be one of the three types.
The inheritance story is different from specialization and worth stating exactly. In specialization, the subclass inherits the union of all the superclass attributes. In a category, the superclasses are disjoint, so the category cannot inherit attributes wholesale — instead, each member of the category keeps its own attributes in its own entity type, and the category contributes only the attributes that apply to every member (in the example, the owner's registration and license details). Attribute mapping to the relational schema follows the same logic: the category becomes a relation whose primary key is the union of the keys of the member superclasses — for OWNER, the SSN of a person owner, the bank code of a bank owner, and the registration number of a company owner — or, in many designs, a single surrogate owner ID that the application guarantees unique across all three member types. Each member superclass relation keeps its own key as its primary key and refers to the category's key as a foreign key.
The practical rule the designer needs: use a category when a requirement says "any one of these different kinds of things" — a vehicle can be owned by a person, bank, or company; a property can be owned or rented by a person or an organization; an insured item can be a house, a car, or a person. Use specialization when the requirement says "this one kind of thing, divided into kinds" — an employee that is a secretary or an engineer. Category answers union; specialization answers partition.
3.5.5 Student Questions and Answers
Q: Can the relationship be more than ternary?
A: Of course, if required you can have it. Try to make it with two, if not three. But this makes it very complicated. Generally, we don't experience it in normal life.
Q: When there is a ternary, non-binary relationship, can we specify cardinality?
A: Good — very good question. First, for the context: there are two things in this — degree and cardinality. The degree is whether it is binary, ternary, or something more. What you are asking about is the cardinality — is it one-to-one, one-to-many, many-to-one? When you look at that particular relationship, even if there is one arrow, you may say many of them are participating, but generally it is two-way. How complex it goes, even for me to speak — you can appreciate how difficult it is in real life. That's why we avoid more than two. If there is a project and a guide that are related, and I put a constraint that there is one student — where do the arrows go? The student is one, but do I put an arrow here or there? It is very, very difficult to put. So we say the student needs to participate only once per instructor per project — I put two arrows here. But does that mean the instructor can also take only one student in one project? That goes in a very different tangent. Till everything is many-to-many, no issues — many students, many projects, that's okay. But as soon as a "one" comes across, there brings about ambiguity. That's why we try to avoid more than binary, more than ternary — because it's difficult even to read what the person has specified. So although we can say it is a cardinality, it loses its charm and detailing when we go to ternary.
Q: Does the extended ER model come after the original ER model is developed?
A: No, no. It's simultaneous. Whenever it is required, you can form it. There are some other bags in your armour that you can use to shoot — some different arsenal whenever it is required. It's the same concept: whenever you require it, use it; you don't require it, don't use it. Don't try to overcomplicate it.
Recap + bridge: A ternary relationship is a set of triples that cannot be rebuilt from its binary parts; its cardinality is genuinely hard to read, so designers default to binary. The category (union type) handles "any one of several different kinds of things" and maps to a relation with a surrogate key when the member keys differ. Now the payoff of all this vocabulary: converting the ER diagram into a relational schema — where every entity and every relationship becomes a table.
3.6 From ER Diagram to Relational Schema
3.6.1 Entity to Relation
Hook: The client has nodded at your ER diagram. Now the picture must become something a database can actually store — a set of tables. The good news: the conversion is almost mechanical. Almost.
Now that we know how the ER model looks, the next step is converting the ER model to the relational model. If this is an entity, the entity is directly converted into a relation. When we say a relation, we mean the relational model's relation — which somebody may also signify as a table. The entity name becomes the relation name — the department entity becomes the department relation. What are the attributes? The same ones. Which one becomes the primary key or the candidate key? The same one that was the key in the ER diagram. Directly, no problem. Similarly, all of them can easily be converted.
Formalize: the mapping rule for strong entities
For each regular (strong) entity type in the ER schema, create a relation that carries the same name as , with one attribute per simple attribute of (composite attributes are flattened into their simple components). Choose one of the key attributes of as the primary key of . Every other key of survives as a secondary (unique) key of .
Weak entities follow a slightly different rule: the weak entity's relation takes the owner's primary key as a foreign key, and the primary key of the relation is the combination of the owner's key and the weak entity's partial key. For section with owner course:
with primary key , and a foreign key referencing course.
In the first step, all the entities and all the relationships can be converted into relations — everything is going to get converted into a table. Then, later on, we say: yes, I did it, but two of them don't need to exist separately — we can mix and match them. That is how it goes.
The whole conversion, in one reference table:
| ER construct | Relational result |
|---|---|
| Strong entity type | Entity relation (entity name = relation name, key = primary key) |
| Weak entity type | Relation = weak attributes + owner's key; primary key = owner key + partial key |
| Binary 1:1 / 1:N relationship | Foreign key on one side (or a separate relationship relation) |
| Binary M:N relationship | Separate relationship relation with both keys; primary key = both |
| N-ary relationship | Relationship relation with foreign keys |
| Multivalued attribute | Separate relation (attribute + owner's key); primary key = both |
3.6.2 Multivalued Attributes
The only thing to remember is the multivalued attribute. For example, day, start date, and end date of a time slot are multivalued. You have two options. Option one: have them as part of the key — time slot, day, start date, and end date together become the primary key. Option two: keep the primary key as is and create a separate relation to store them if they are multivalued.
Worked example: the student with many phone numbers
There is a student with ID number, name, and total credit — and a multivalued attribute, phone number. To convert that into a relation you have two options.
Option 1 — fold the multivalued attribute into the entity relation. The relation has ID, name, total credit, and phone number, where ID and phone number together become the primary key. The cost: the student's name and total credit are repeated once for every phone number they own.
Option 2 — a separate relation. Keep the student relation as it is (ID, name, total credit) with primary key ID, and create a separate relation for student phone number:
where ID and phone number are the prime attributes — both form the primary key of this new relation — and ID is a foreign key referencing student.
Work it with real numbers. Student ID 22222 (Einstein, Physics) has two phones, 555-1234 and 555-4321. Option 2 stores:
| ID | phone_number |
|---|---|
| 22222 | 555-1234 |
| 22222 | 555-4321 |
Sense-check: with option 2, each phone lives in its own tuple, the student's other attributes are stored exactly once, and no attribute in this table is ever multivalued — which is exactly what the relational model wants.
3.6.3 Relationship to Relation
When we have a relationship to convert, the relationship will have the keys of both sides as its attributes — the key here and the key there. Then we convert it into a relation, because that is how we capture that a student is related to a department: how else do we store the relation? Where we store its keys, which are part of it. What becomes the primary key of that relation is decided by us — by reasoning, not by cramming.
Worked example: advisor — the many-to-one case
Think it through with the student-department relationship. A student can be related to at most one department. So whenever the relation's records come in — with the department name and the student ID — the student ID appears at most once; it cannot repeat, because the relationship itself says a student is related to a department at most once. However, the entry for the department can repeat, because a department can be related to more than one student. So in this particular relation we will have repetition of the department, but the student appears only once. That is why, with the two attributes department name and student ID, the primary key is the student ID only.
Similarly, while reducing the advisor relationship: the relation will have a student ID and an instructor ID. However, the primary key is the student ID, because the student can appear at most once in that particular table:
So you may think of it as: in a one-to-many relationship, the key goes on the many side. But don't cram it — the more you understand why, the more heartily and correctly you will do it every time. The why is simple: the primary key is the set of attributes that appears at most once per record, and in a one-to-many relationship, the many side is the one that cannot repeat.
Worked example: section-course — the weak entity's relationship
Now for the section-course case: what is the relation for the section-course relationship? It will have section ID, semester, year, and the course ID — four attributes. When we write the section relation, it has four attributes, and all four of them are part of the key: course ID, section ID, semester, and year. For the section-course relation, I include the key of section — the same one, because the course ID was already part of it. And the primary key will be the key on the section side, because it will appear at most once in this particular relation.
Sense-check against the weak-entity rule from 3.6.1: section is weak, its full key is exactly — the section relation and the section-course relation hold the same four attributes. We will see in 3.6.4 what to do about that duplication.
Worked example: teaches — the many-to-many case
For teaches: teaches relates an instructor to a section. The key for the section entity is course ID, section ID, semester, and year. The key for the instructor entity is the instructor ID. Because it is a many-to-many relationship, all of them can repeat — there can be multiple sections appearing when we store the records, and for every section there can be multiple instructors. So to make sure everything is unique, everything is part of the key: the teaches relation has the instructor ID, course ID, section ID, semester, and year, and all of them together form the primary key. Individually they cannot be the key — the instructor ID alone repeats (one instructor teaches many sections), and the section key alone repeats (one section has many instructors). Only the full combination is guaranteed unique.
For takes: the takes relationship relates a student and a section. The relation includes the student ID and the section key — course ID, section ID, semester, year — plus the relationship's attribute grade. Because it is many-to-many, the primary key of this side and the key of that side together form the key for the relationship relation:
The grade, being an attribute, is not part of the key — a student can have only one grade per section, so the key attributes alone already identify each record.
Exam note (from the professor): do not cram these conversion rules. The primary key of a relationship relation follows from one question — which side can appear at most once? In a one-to-many, the key is the many side. In a many-to-many, neither side is at-most-once, so both keys together form the key. Reason it out, and you will be right every time.
What about attributes with null values? Don't worry about null values here: except for the key, everything can be null. Everything is allowed to be null except the key.
One clarification that came up repeatedly: the entity section and the relation section course have the same attributes, and sec class and sec time slot are not part of the takes relation. Why? Because the owner entity of section is only one — the course. That is why the double rhombus is on that one side. Its owner entity defines its primary key: course ID, section ID, semester, and year. After that, section is a unique entity in itself. So when the takes relationship is there with section, section has its key — course ID, section ID, semester, year — and that's it. Other entities section is associated with take part as normal entities, not as owner entities. Section has only one owner entity which defines its key.
3.6.4 Reducing Redundancy
Now the discussion that followed: the student-department relation and the student relation. There are two things we need to avoid. One: there should be the least amount of redundancy — that means if the same thing is stored twice, we are misusing the storage. Two: what about consistency? If I am storing the student ID and the student name in the student table, and there is another table in which I am storing the student ID and name as well, then at one point of time the student decides to change the name. Suppose my name was Amit Dua and I decide to change it to Amit Kumar Dua. Now if there is redundancy, it may be possible that the two different tables tell two different things — who will you believe in that particular case? We need to ensure that every time we update, everything in the redundancy is updated; if anything is off, there is chaos, we cannot believe anything. So redundancy has more to do with consistency — with the certainty of what we derive.
Scope: Redundancy is not a cardinal sin on its own — the danger is that it silently breaks consistency. Every duplicated fact must be updated in every copy at every change, and any missed copy leaves the database telling two different stories. Normalization (first, second, third normal form, BCNF) attacks exactly this problem with a formal theory, and the professor's point here is that the relational schema can already be tidied by hand — reduction of redundant relations — before normalization is even taught.
In this case: all the students are stored in the student table. The student-department relation has an ID and a department name. Because a student can be related to at most one department, and every student is related to some department, all the students in the student table will also appear in this particular table — with exactly one entry each. So there is redundancy: something extra is being stored. Tomorrow, if the student's ID gets changed — it happens; students sometimes have a vertical or a horizontal transfer. Initially a student was assigned to computer science, and later decides to do mechanical; by the dint of very good grades a student can apply and transfer the stream. Or a student joined the campus premise on an MSc program — physics, chemistry, biology, mathematics, or economics — and based on the performance of the first year, they are given the basic graduation course, civil, chemical, mechanical, computer, or electrical. In the second year their ID changes every time: initially they had something like 2023 B4 PS, where B4 means mathematics; later they become B4 A7, where A7 means computer science, with their ID numbers changed. Even an employee's ID number, let's say 1234, can change for whatever reasons. Now the same ID number is stored in the student table and in the other table as well. There is a redundancy, and that may lead to unnecessary storage space — at least in this particular case, not a consistency violation. I have to at least change two places whenever I am related, without any particular saving. So I can easily make a single table out of it — a student-department table — just to ensure there is the least amount of redundancy. Somebody may say whatever normalization will come across will fix it, but primarily from the redundancy aspect we can still reduce the relational schema.
Similarly for section-course: everything in section is in section-course as well — all the attributes are the same — so it does not make sense to have two tables. By default, we have just come across: wherever there is a many-to-one relation where the entity on the many side is participating, we can reduce two relations into one.
Recap + bridge: Entity → relation, multivalued attribute → either part of the key or its own relation, relationship → relation with the keys of both sides, primary key decided by "which side appears at most once," and redundant pairings merged (many-to-one with total participation on the many side). This last rule is the manual preview of normalization. The next section asks the deeper question the whole model rests on: what exactly is a relation?
3.6.5 Student Questions and Answers
Q: What about the attributes with null values? And shouldn't there be a one-to-one relation with a student in a project also?
A: The relation is between the requirements. If the requirement is specified, it is based on the requirement — it is not based upon should or should not. The mini world is given by the client; the client tells it. What about attributes with null values? Don't go into null values here — except from the key, everything can be null. Everything is allowed to be null. That is what it is.
Q: For the teaches part, why is the primary key the combination mentioned in the relationship on the right? Individually, can the keys be the primary key?
A: First understand what teaches is related to: teaches is related to the entity section. According to our rule, the teaches relation has the key at this side and the key at that side as its attributes. The key for section is course ID, section ID, semester, and year. The key for the instructor is the instructor ID. Because it is a many-to-many one, all of them can repeat — so everything will be part of the key. All of them together will be a primary key. Individually it can't be there: the key for section is all four of them together, the key for the instructor entity is one, and because it is many-to-many, everything can repeat — there can be multiple sections appearing when we store the records, and for every section there can be multiple instructors. So to make sure everything is unique, everything is a part of the key.
Q: The entity section and the relation section course both have the same attributes. Why?
A: Yes — that is the next part for it. There is redundancy — you have a lead, a leading question. Section course has all the attributes of sections, and everything which is in sections is in section course as well. So it does not make sense to have two tables. Wherever there is a many-to-one relation where the entity on the many side is participating, we can reduce that rather than having two — this two can be a one relation. That's how we can even minimize the number of relations here.
Q: In the takes relation, you included the student ID and the section key, but sec class and sec time slot were not taken. Any specific reason — like we have to choose sec class building line key or time slot ID?
A: No — because the owner entity is only this one. This entity, which is there, has only one owner entity; that is why the double rhombus was on one side. Its owner entity will define its primary key: course ID, section ID, semester, and year. Others, wherever they are associated with, will take part as a normal entity. After that, section is a unique entity in itself — its key is course ID, section ID, semester, and year. When the takes relationship is there with section, section has its key and the student has its ID, and there is the entity grade for that relationship. Because it is many-to-many, the primary key of this side and the key of that side both form the key for that relationship's relation. Grade, being an attribute, is not part of the key.
Q: The ER model is a graphical representation — relation to relation, if you have to say, is like a function kind of representation: name and then what is passed on. Am I right, or is anything else to be done to explain?
A: Nothing like that. A relationship is always related to some capsule, one or two or many entities, that you can form to have a relation with others. That was a separate case: three different entities combined together and related to another entity. Say we have a student, an instructor, and a project — that may have a relation to another entity called evaluation. Either you have a relation with all three of them as a fourth one, or you can encapsulate it in a box and then relate that. That is it. A relation is always with a particular entity — one, two, or many of them. I have not come across relation-to-relation; I think that is not allowed even here.
Q: In the word file you shared, these things are represented as two different schemas. Are we saying one schema with all the things in the rectangular boxes — the entities and the relationships?
A: Ignore the word representation — the file got corrupted when converting. Focus on the class and the text. The ER diagram itself is the conceptual schema — the entity-relationship model is the principles used to convert into this conceptual schema. In the first step, every entity and every relationship is converted into a relation, a table. Then we see which two don't need to exist separately and mix and match them.
Q: Can we update or change the primary key of any table?
A: When we come to the relational schema, I will tell you how it is done — you will see it in SQL, when you do the programming you can think about it. Generally, it is a decision which has to be done at the design stage. Once we have taken a decision, it is the decision. However, there are some update clauses — you can update the table as well. From the implementation point of view, the user decides once that yes, I will have student ID number as unique. But later on, after one year or two, as the application grew and the ID numbers stopped being unique or something like that, you may have to take a decision on how they are actually stored or implemented — you can update that particular constraint.
Q: Suppose a government employee works in one school but she can also work in another school on deputation. How do we model that?
A: Your question is more related to the requirement specification. Based upon the requirement specification, your diagram will change. If your requirement specification is like that — initially you specify how the teacher is related to the schools — then based upon that you can create a different diagram. How it will be different based upon different requirements is a detail we haven't started on yet; it is already over an hour into the topic. Whatever the practical thing, how the scenario changes, might be difficult to take right now — but the principle is clear: the requirement specification drives the diagram.
3.7 The Relational Model
3.7.1 Everything Is a Relation
Hook: In the 1970s, database systems were built like giant filing trees — and programmers were drowning. One researcher simplified everything to a single idea: everything is a table. The idea was so powerful that it won computing's highest prize.
The relational model is the one we have just converted the ER diagram into. The basic premise is that everything is a relation. That's it. This is inspired from Edgar F. Codd's paper — and because of this paper, he was awarded the Turing award. It is a very fundamental paper, so understand the beauty of it. People were trying many different things earlier — the network model, or some other model. Codd gave a very simple understanding, which was really very fundamental. In the 1970s some principle was formed, and till today — 60, 50 years later — the same principles are used. That is why he was awarded the Turing award: that is the beauty of classic fundamental principles — the applications and advancements keep on happening on top of them.
And the situation is like the house again: where do I store my books, where do I store my bedsheets, where do I store my entire clothes, where do I store my keys, where do I store my daily course items in the house, and how do I store everything else? That was the problem in the 1970s — and still now, in the real life of many people — analogous to the problem with data. In the relational schema, everything is a relation, and the relation looks like a table with rows. That is how it will be stored.
Formalize: what a relation is
A relation consists of two things: a relation schema and a relation instance (state). The schema is the column heads — the relation's name, the name of each field (attribute), and the domain of each field. The instance is the actual set of rows at a point in time. When someone says "the student relation," they usually mean both: the definition and the current content.
The formal picture: for a schema , an instance is a set of tuples
Two measures describe any instance: the degree of the relation (the number of fields, — the number of columns) and the cardinality of the instance (the number of tuples, — the number of rows). Do not confuse these with the degree and cardinality of relationships from 3.5 — same words, different meanings, different worlds.
3.7.2 Relations, Tuples, Domains and First Normal Form
The relation name is student; it has different attributes; these are different tuples; and that is how we denote it across. The domain of a relation is inspired from the fact that we are using first normal form. First normal form is the normal form where we say every entry in a particular tuple's attribute is unique — I cannot have multiple entries here. By default it is minimal and it is unique. That is what we are trying to work upon.
Formalize: attributes, tuples, domains, and 1NF
- An attribute (also called a field or column) is one named piece of data in a relation — for student: ID, name, total credit.
- A tuple (also called a record) is one row: one value for every attribute, in the same order as the schema.
- A domain is the set of all values an attribute is allowed to hold — the possible set of values that particular attribute can store. If I am storing an integer domain, then everything related to integers — or a float, or a where clause — whatever is possible can be stored in that particular table. Some things may come across in a year format or in an address format, you can think of it that way. What all can be possibly stored in that particular attribute is the domain of that particular attribute. There are mathematical definitions, but this is what it signifies.
First normal form (1NF) is the rule that every attribute value is atomic — a single indivisible value, never a list, never a set, never a nested record. This is not a refinement you may skip: 1NF is implicit in the definition of the relational model itself. That is exactly why section 3.6 created a separate relation for the student's phone numbers instead of storing a list of phones inside one attribute.
In loose format: when we say table, actually it means a relation; when we say column header, that is an attribute; what can possibly be stored in a column's values is the domain; and the rows are the tuples.
Worked example: reading a relation
Take the schema — degree 5 (five fields). One possible instance, cardinality 6:
| sid | name | login | age | gpa |
|---|---|---|---|---|
| 53831 | Madayan | madayan@music | 11 | 1.8 |
| 53832 | Guldu | guldu@music | 12 | 2.0 |
| 53688 | Smith | smith@ee | 18 | 3.2 |
| 53650 | Smith | smith@math | 19 | 3.8 |
| 53666 | Jones | jones@cs | 18 | 3.4 |
| 50000 | Dave | dave@cs | 19 | 3.3 |
Read it aloud: the domain of age is the set of integers; the domain of gpa is the set of real numbers; each row is one tuple; each tuple's age cell holds exactly one number — atomic, so the instance is in first normal form. Notice the two Smith rows: the name value repeats, and that is fine — a relation demands uniqueness of whole tuples, not of attribute values. Also notice the tuples could be listed in any order and the relation would be identical.
3.7.3 Schema versus State
The table definition — how we are defining the table — is the schema of the relation. When we say student has an ID and a name, whatever we write across, that is the schema. And once the schema is populated, it is the state of the relation — with the values being populated. So the state is where not only we are defining the attributes but also the values that are stored.
Scope: Schema and state are the design time and the running time of the same table. The schema is stable — it changes only when the design changes (a new attribute is added, a constraint is tightened). The state changes with every insert, update, and delete — it is the living content. The ER diagram from 3.3 lives entirely at the schema level: it is "just an idea of what the user specified," with nothing populated. That is why the ER picture never shows data values — the data arrives only when the relational state is filled.
3.7.4 Table versus Relation
There is a difference between a table and a relation, and we need to understand it. Although we say a relation is represented like a table, in a table we can have repetitions and there is an ordering. But in a relation we don't have ordering — neither across tuples nor within attributes — and we don't accept repetitions either. Once they are defined, of course, we need to respect how they are stored properly. But the relation itself has no ordering, and no two records can be the same, because it is a set.
Recap + bridge: The relational model is one idea — everything is a relation — plus a small vocabulary (schema, state, tuple, attribute, domain, degree, cardinality) and two iron rules: atomic values (1NF) and set semantics (no duplicates, no ordering). This last point — why ordering and duplicates are forbidden — becomes the foundation of the next topic: the constraints that keep a relation honest.
3.7.5 Student Questions and Answers
Q: The tuple can be called a record also, right?
A: Yes — in loose terms we say the first record, the second record; in normal terms we say tuple. You are right.
Q: Are entity and relation used synonymously here?
A: In this particular world of the relational schema, we have relations. The entity was in the entity-relationship diagram — we left that world a few minutes ago. The user gives the requirement, we convert it into an entity-relationship model where there are only entities and relationships, and then we convert it into a relational schema, wherein in this world we have relations, attributes, and tuples. And how the relations and entities or relationships are related — we have just converted the ER diagram to this particular form. Also, in the ER diagram there was nothing populated — it was just an idea of what the user specified. The ER diagram has nothing to do with populated values; it is just a way to capture the user requirement into a form the user finds okay.
3.8 Relational Constraints
3.8.1 Three Kinds of Constraints
Hook: A relation alone stores data — but a database you can trust is one where bad data cannot get in. Who enforces the rules? The answer has three layers, and knowing which layer does what is a classic exam question.
The different constraints are very important to discuss — take it as a very important thing. Some of them are implicit constraints: for example, we need to store only unique values in every attribute, or every attribute of a tuple that I consider — it is unique, we cannot store two things. That is an inherent constraint that the schema presents to us. Some of them are explicit, schema-based constraints: this is a primary key, this is a non-null attribute, something like that. Some of them are application-based: those will have to be handled at the programming side. For example, you may want to ensure that the salary of a manager has to be higher than the salary of his or her subordinate — the subordinate's salary should be lesser than the manager's salary. Or, in this particular world, whenever somebody graduates, his or her salary should be higher than the professor's salary — in a fantasy world. Something can happen depending upon that requirement; that is an application-side requirement.
Formalize: the three-way classification
- Implicit (inherent, model-based) constraints — built into the data model itself, no one writes them. The rule "a relation cannot contain duplicate tuples" is an implicit constraint; so is "every attribute value is atomic" (1NF from 3.7). They hold in every relation of every database, by definition.
- Explicit (schema-based) constraints — written into the schema, usually in the data-definition language (DDL): primary key declarations, not-null attributes, foreign keys, unique keys, check conditions. The DBMS enforces these by itself, on every insert, update, and delete.
- Application-based (semantic, business-rule) constraints — the meaning of the data itself: "the salary of a manager must exceed the salary of each subordinate," "an employee works at most 56 hours per week." These cannot be expressed as simple schema clauses, so the application programs (or triggers/assertions, when available) must check them at update time.
3.8.2 Integrity Constraints
Then there are the relational integrity constraints. There are key constraints — constraints on the side of something related to an entity. Primary key, secondary key, candidate key — these are also called entity integrity constraints. Some of the constraints are referential integrity constraints, and some are domain constraints: I need to ensure that there is no null; I also need to ensure that an attribute can only store integers, or only strings, if the domain is like that. For example, if this is an SSN number, and the domain is integer or the format is like that, I need to respect that — I cannot store the SSN number as "Amitua". That is another constraint that I need to respect here.
Formalize: the four integrity constraint families
- Key constraints (entity integrity): every relation has a key, and no primary key value can be NULL — a NULL primary key would leave a tuple unidentifiable, and two NULL keys might be indistinguishable. Key constraints live on individual relations. (T2's phrasing: null values are not allowed in a primary key field.)
- Referential integrity: a tuple in one relation that refers to another relation must refer to an existing tuple in that relation. This is the formal face of the foreign key idea from 3.4 — the value either matches a primary key value in the referenced relation, or it is NULL (and NULL is banned where the attribute is part of the primary key).
- Domain constraints: every attribute value must come from the attribute's domain. An SSN column with an integer domain cannot hold "Amitua", and an account number with a numeric domain cannot hold a name.
- Not-null constraints: an attribute declared NOT NULL cannot be given a NULL value at all. By default, primary keys carry the not-null constraint. Something like — if I want to ensure that I always store the model year, because for some reason after 15 years you cannot drive, or there is a tax list and that — this is a not-null constraint. Before entering, the user cannot give this entry as null. That is also a constraint that we can have.
For the domain: some constraints are related to a super key or a key — we already know how to apply those. Some constraints also say how to read the constraint for the key.
3.8.3 Reading a Key Constraint
Let's suppose the key is engine serial number and make together — hypothetically assuming, assuming, assuming, all of you. In that particular case, what do I mean by saying this set of them will always be unique? This is what I am saying: anything is unique. Because it is a relation, no two particular records can be the same. And also, the order does not matter — license number, serial number, engine number, make, model: there is no ordering either across different tuples or within different attributes. Once they are defined, we need to respect how they are stored properly, but the ordering is not part of the relation.
Worked example: engine serial number and make
Declare the key of the car relation to be the pair (engine serial number, make). Concretely, let the relation hold these records:
| engine_serial | make | model |
|---|---|---|
| 123456 | Ford | Fiesta |
| 654321 | Toyota | Corolla |
| 123456 | Toyota | Camry |
| 654321 | Ford | Fiesta |
- Record 3 has the same engine serial as record 1 — allowed, because the pair (serial, make) is what must be unique, and the makes differ.
- Check all four pairs: (123456, Ford), (654321, Toyota), (123456, Toyota), (654321, Ford) — all four pairs are distinct, so the key constraint holds even though both attributes repeat individually.
- Now try to insert (123456, Ford, Focus): the pair (123456, Ford) already exists as record 1, so the insert violates the key constraint and must be rejected. The DBMS enforces this automatically — no application code needed.
Sense-check: this is a key (not merely a superkey) if neither attribute alone is unique — which the table shows: 123456 repeats, and Ford repeats.
3.8.4 Student Questions and Answers
Q: In a realistic scenario like a student table or a banking application, the primary key is the user's account number. When creating a new account, it cannot be null — and can the user's name be null? And what about the domain?
A: The primary key is the account number, and it cannot be null. But even though the primary key is the account number, the user name is not null: every account number has to have a name as well. That is a practical aspect for it. The domain: the account number is a numerical value, so it is an integer one — at least in the Indian scenario, you cannot have "Amitdua" as an account number, or "Gautam Kumar" as an account number. And similarly, for the user name, you cannot have "123457810" as the name — that is not acceptable. So you understand the domain constraints, the not-null constraints, and also the constraint for the primary key.
Recap + bridge: Constraints come in three layers — implicit (the model itself), explicit (schema clauses), and application-based (business rules in code) — and the relational integrity families are entity integrity (no NULL keys), referential integrity (refer only to existing tuples), domain constraints (values from the right domain), and not-null constraints. The next section drills into the most subtle of these: the foreign key, its delete options, and its self-referencing form.
3.9 The Foreign Key Constraint in Detail
3.9.1 The Works On Example
Hook: "References" is the most important word in relational design. One table promises: everything I point at, you must have. What happens when the thing being pointed at disappears? That is the foreign key story.
The very important thing coming across is the foreign key constraint. In the company schema, the employee relation has SSN as the primary key, and the department relation has the department name as the primary key. There is also a works_on relation. When we write the works_on relation, the project number here references the attribute P number in the project relation. Why do I say references? The foreign key in this particular relation is the P number, which is referencing the P number in the project relation. Because of the fact that I want to store here the P number only for the projects which exist, and also want to keep a constraint that whenever somebody deletes the P number from the project, either that can be deleted, or I restrict that, or I store a default value there.
Formalize: the foreign key
A foreign key is an attribute (or set of attributes) in one relation — the referencing relation — whose values must appear as the primary key values of another relation — the referenced relation. In the company schema:
with a foreign key referencing PROJECT() and a foreign key referencing EMPLOYEE(). The basic purpose of a foreign key is simple: whatever the entries are there, if it is referring to something, the entry should be there. Whenever somebody wants to delete a P number in the project, first of all, all the P numbers existing here must exist here — that is the first thing for a foreign key. Secondly, it is a constraint that if somebody wants to delete the P number in the project which is referenced by a foreign key, then either I restrict the deletion because there is an entry here, or I cascadingly delete — whenever it is deleted, everything is deleted here, all the entries with the same P number — or I store a default value here: if that is deleted, store a default value. In either of these things, the foreign key is limited — the foreign key is important.
In SQL, the constraint is written once at table creation, and the engine enforces it on every command:
CREATE TABLE WORKS_ON (
Essn CHAR(9) NOT NULL,
Pno INT NOT NULL,
Hours DECIMAL(3,1),
PRIMARY KEY (Essn, Pno),
FOREIGN KEY (Essn) REFERENCES EMPLOYEE (Ssn) ON DELETE CASCADE,
FOREIGN KEY (Pno) REFERENCES PROJECT (Pnumber) ON DELETE CASCADE
);
Worked example: the P number references the P number
Three small instances:
| PROJECT: Pnumber | Pname | WORKS_ON: Essn | Pno | Hours | |
|---|---|---|---|---|---|
| P1 | ProductX | 123456789 | P1 | 32.5 | |
| P2 | ProductY | 453453453 | P1 | 20.0 | |
| 123456789 | P2 | 8.0 |
- Insert (987654321, P9, 10.0): rejected — P9 is not a Pnumber in PROJECT. This is the insert rule: the foreign key value must exist in the referenced relation.
- Insert (123456789, P2, 15.0): rejected too — the pair (Essn, Pno) = (123456789, P2) already exists; the primary key clause rejects it. An employee can hold at most one row per project.
- Delete P1 from PROJECT: the engine looks at WORKS_ON and finds two rows with Pno = P1. What happens now is chosen by the delete option — the next subsection.
3.9.2 Delete Options: Restrict, Cascade, Set Default
So when a record in the project table that has records in works_on is to be deleted, we have three options: either we should not allow it — restrict; or we have to cascade — delete the referencing entries too; or we choose a default value. The default value must exist in the referenced table — otherwise the foreign key will not be valid. For example, if a manager leaves and the CEO is the manager, you can think of it here: that default exists, and the foreign key will hold. If it is not there, then the foreign key will not hold.
Formalize: the three (really four) delete options
- Restrict (no action): the deletion is rejected while referencing tuples exist. Project P1 cannot be deleted while WORKS_ON holds rows with Pno = P1. This is the default in standard SQL.
- Cascade: the deletion propagates — deleting P1 deletes every WORKS_ON row with Pno = P1. The cascade chains: if another relation references WORKS_ON, its rows go too, and so on.
- Set default: the referencing values are rewritten to a declared default — but the default value must itself exist in the referenced table, or the foreign key would be violated by the very action meant to fix the violation. If the default does not exist, the operation is rejected.
- Set null: (the fourth, standard option) the referencing values are rewritten to NULL — allowed only where the foreign key column is nullable; a foreign key that is part of a primary key can never be set to null, or it would break entity integrity.
At the time of deciding, we need to tell whether it is a restricted one, a cascade on delete, or a default one. While storing, we need to specify the constraint, or we need to have some assertions. For example, if an employee was working on two projects, we don't allow deleting the project — ideally it would be the restrict one, because it is related to this one as well. If there is nothing here, nothing there, no problem — it is a key as well. It depends upon how the administrator decides to use it.
Worked example: deleting a completed project
Employee E1 works on P1; the project is complete; the tuples must be removed from works_on and from project — that is the cascading deletion. Whenever something gets over, it may be cascading delete: not only delete from the project here, you delete from works_on as well — all the employees who were working on it will no longer have an entry.
But if a department gets dissolved, that is an application-level issue, because it may have multiple cascading effects. You really need to think through what you will do if you say cascading delete, because there may be conflicts: you may say there is a cascading delete here, and here you may say no, no, there is a restrict because of an entry location. As an administrator, as a designer, you have to take care of it while dealing with it. It rolls over to all four tables — that is where the cascading solution has some trouble, and that is the responsibility of the designer: should you use restrict, should you use cascading delete, or should you use a default one? Trace it with the company schema: deleting the department that manages projects touches DEPARTMENT, PROJECT (its Dnum), WORKS_ON (rows for those projects), and EMPLOYEE (its Dno) — four tables, four chances to pick the wrong option.
3.9.3 Self-Referencing Foreign Keys
Sometimes the foreign key refers to the same relation as well. You can relate to it: the employee relation has SSN and super SSN — the super SSN is a foreign key referring to the SSN of the same relation. If I am storing my data, I am also storing within my data my manager's data: super SSN is the manager's SSN — who is managing me. But it is important that the manager must also be an employee — that's why the information is different in the column. It is my information; it is my manager's information; but the manager also has to be an employee. There might be a manager table, or there might not be — in this case, in this table only, we are storing who is my manager. It is a way to tell that there is a foreign key which can refer to the same relation. Similarly, you may think of a D number referring to the department relation, or a manager SSN, and so on and so forth. Sometimes in the relational schema we not only represent the relation and the attributes, but also can represent the foreign keys as well.
Worked example: the manager must be an employee
In the EMPLOYEE table, John Smith has SSN 123456789 and Super_ssn 333445555 — meaning Franklin Wong (SSN 333445555) is John's manager. The president of the company, James Borg, has Super_ssn NULL — nobody manages the manager of all.
| Ssn | Fname | Super_ssn |
|---|---|---|
| 123456789 | John | 333445555 |
| 333445555 | Franklin | 888665555 |
| 888665555 | James | NULL |
The same real-world concept (a social security number) appears twice in one relation, so the two roles get two names: Ssn for "the employee's own SSN" and Super_ssn for "the manager's SSN." Every value in Super_ssn must exist as an Ssn in the same table — the manager must be an employee — and the president's NULL tells you the referencing column is nullable.
How can the two be the same? How can I be the manager of myself? In this particular case both cannot be same. The manager is also an employee; I am also an employee, but the column tells who is my manager. The super SSN is not a replica of the SSN — understand the purpose of the foreign key: it says that whenever I am having any foreign key here, whatever the entries are there must have an entry here. That is the basic relation, the basic purpose of a foreign key. It is not necessary that both are the same.
3.9.4 Where Foreign Keys Come From
In the relational world there is no concept of an entity in itself: this is a relation, and in that relation there are attributes, and these attributes have foreign keys that we denote here. How did the foreign key, which was not in the ER model, come across? The foreign key may come across when we are merging two relations. One of the ways in which a foreign key appears: we have an ER diagram — entity, relationship, another entity — and we formed a three-relation conversion, and we decided that now two of them will become a part of each other. Then we will say: yes, since we are combining them, we will have a foreign key from one of the attributes to the other entity which was there. That is how we denote it across. Even if there is a relationship whose relation or table we are converting in the relational schema, that itself is referring to the primary keys of the individual attributes. If you look at the advisor relation, the relationship between a student and an instructor: in that advisor relation, it has a student ID and an instructor ID. The student ID is referring to the student's relation, and the instructor ID is referring to the instructor relation. Both of them are primary keys there, and both are foreign keys here.
3.9.5 Student Questions and Answers
Q: For the foreign key connecting project and works_on: we said we can insert a record in the works_on table only if it exists in the project table. For deletion of a project that has records in works_on, we have three options — restrict, cascade, or default. Is it a requirement that the default value should also be there in the project table?
A: Good question. In that particular case, it depends upon you as well — these things are provisions that are there. Automatically, when I say default value, the default value must exist; otherwise the foreign key will not be valid. Say nothing is there — suppose a manager leaves and the CEO is the manager here — you can think of it like that. That default exists, so the foreign key will hold. If it is not there, then the foreign key will not hold.
Q: In works_on, employee SSN and project number are the primary ones here. At the time of deciding, we need to tell whether it is a restricted one, a cascade on delete, or a default one — do we need to tell the constraint while storing?
A: Yes — we need to specify the constraint, or we need to have some assertions. For example, if an employee was working on two projects, we don't allow it to delete — ideally it would be the restrict one, because it is related to this one as well. If it is nothing here, nothing there, no problem — it is a key as well. It depends upon how the administrator decides to use it.
Q: In the reference diagram, employees and departments are entities, but you have listed the relations as the schema and not the entities. Are they both separate?
A: They are both separate. The user gives the requirement specification; first we create the entity-relationship diagram to give clarity that everything is clear, because the user might not understand the relational schema — for the user it is like Japanese, Russian, French: what does it mean? That is your responsibility as the application developer — the user says I want to store this, I want to get it whenever required, you handle everything. But the diagram the user can still feel; I can explain that to the user. So first we convert the diagram, then we use the relational schema. And in this relational world there is no concept of an entity in itself: this is a relation, and in that relation there are attributes, and these attributes have a foreign key that we are denoting here. If your question is how the foreign key, which was not in the ER model, came across here — the foreign key may come across when we are merging two relations. One of the ways in which a foreign key comes across: we have an ER diagram — entity, relationship, another entity — we formed a three-relation conversion, and we decided that now two of them will become a part of each other. Then we say: since we are combining them, we will have a foreign key from one of the attributes to the other entity. Even if there is a relationship whose relation we are converting in the relational schema, that itself refers to the primary keys of the individual attributes: in the advisor relation, the student ID refers to the student's relation and the instructor ID refers to the instructor relation — both are primary keys there, both are foreign keys here.
Q: Can we say that to provide a relationship between two entities or two tables, we have to use foreign keys — that foreign keys play the role of relationship between two tables? And in the employee table we have SSN and super SSN, both referring to the same data — what is the purpose?
A: Please don't confuse the relationship here. It is a foreign key; let it be a foreign key only. It has its own way. Don't mix the terminologies — you are creating unnecessary butter on your head. And for SSN and super SSN: if I'm storing my data, I'm also storing within my data my manager's data as well. Super SSN is the manager's SSN — who is managing me? But it is important that the manager must also be an employee. That's why the information is different in the column: it is my information, it is my manager's information, but the manager also has to be an employee. In that case, it's a good question.
Q: Is there any correlation between the candidate key and the foreign key? Must the foreign key be a subset of the candidate key?
A: No, not like that. This is a foreign key. Is it a secondary key? No. It might be possible that some foreign key is not a candidate key — but your question is whether the referenced one is always a key. Yes — generally it is there, because if I am saying something which is not even the key there, then it might be referring to two of them, two different records. Although I cannot say for sure that always, but generally I have seen that they are either the key or the part of the key itself. But it might be possible that they are neither of them as well — hypothetically, suppose SSN is not unique in itself, there are many persons who have the same ID, many persons who have the same manager. It would be chaos in that case, but I cannot give a rule here that always it is there, since I am not confident giving that rule. Generally it is there.
Q: In the employee relation, SSN is the primary key here, but the same thing is acting as a foreign key in the same relation. The records are everything the same — super SSN is the replica of SSN, right?
A: Understand the purpose of the foreign key. The foreign key says that whenever I am having any foreign key here, whatever the entries are there must have an entry here — this is the basic relation, the basic purpose of the foreign key. It is not necessary that both are the same. How can they be the same? How can I be the manager of myself? In this particular case, how can both be same? The manager is also an employee; I am also an employee, but it is related to who is my manager. That's it.
Q: In the SSN case, SSN is universal for both manager and employees — a normal identifier — and we refer to it via super SSN. Do we have a manager's table or something?
A: There might be a manager table, might not be. In this case, in this table only, I am storing who is my manager. Real world, whatever will happen, but in this case we are storing the relation for the manager in the table of the employee. Don't worry about normalization or other aspects here — it's just a way to tell that there is a foreign key which can be related to the same relation.
Q: Suppose I am employee E1, working in department D1, on project P1. My project gets completed — the tuple needs to be deleted from works_on and from project. That is the cascading deletion you are talking about. And if a department gets dissolved, how is the cascading going to happen?
A: Yes, good — whenever something gets over, it may be cascading delete as well. If you want to delete the project because the project is over, not only delete from the project here — you delete from works_on as well; all the employees who are working on it will also not be there in an entry. And when a department gets dissolved, that is an application-level issue, because it may have multiple cascading effects. You really need to think through what you will do if you say cascading delete — there may be some conflicts as well. You may say there is a cascading delete here, and here you say no, no, there is a restrict — that is an entry location which might be something. As an administrator, as a designer, you have to take care of it while dealing with it. It rolls over to all four tables — that's where the cascading solution has a little trouble — and that's the responsibility of the designer: should you use restrict, should you use cascading delete, or should you use a default one?
Recap + bridge: A foreign key says "every value I hold must exist in the referenced relation" — that is referential integrity in action. Deletion of a referenced row forces a choice (restrict, cascade, set default, set null), the default value must itself exist, and the foreign key may even reference its own relation, as SUPER_SSN references SSN. All of this is the relational world answering the questions that the ER diagram could only picture. Last stop: how relational and document worlds differ when the constraints loosen.
3.10 Relational versus NoSQL and Document Databases
3.10.1 The Postgres JSON Question
Hook: Everything so far says: one attribute, one atomic value, and no exceptions. Then a student reports that Postgres — a real product — stores whole key-value sets inside a single attribute. Is the relational model broken?
Generally we learn in the relational model that the attribute should have only one value — we cannot store multiple values in the same attribute. But practically, in one implementation in Postgres in some organizations, there is a data type called JSON, which is given as one of the fields, and the organization actually stores a set of key-value pairs in the same attribute. Is this an exception, or is the implementation itself something different?
The response: first of all, a confession — I have not worked on Postgres. Secondly, there are different types of storage as well. What we are showing is the relational one. However, the key-value pair is a document database, generally — in a document database like Cassandra, we have a key-value pair, which is a NoSQL relation. NoSQL means the constraints for the relational model do not apply in that world. They generally use JSON, or binary BSON — the binary version of JSON — which is MongoDB, another version of that. So the constraints we are discussing here in the relational one would be differently applied in that one.
Formalize: JSON as a data type, and what it is not
In the relational world, integer, float, and string are data types, and every attribute holds one atomic value (1NF, from 3.7). In the document world, the data type itself is a JSON object — a set of key-value pairs — and it is stored as one field. An example document:
{
"ID": "22222",
"name": { "firstname": "Albert", "lastname": "Einstein" },
"deptname": "Physics",
"children": [ { "firstname": "Hans", "lastname": "Einstein" } ]
}
A relational table would flatten this into columns (ID, firstname, lastname, deptname, ...) with one row per child; the JSON field keeps the nesting as-is. So a JSON column in a relational product is not a violation of the relational model — it is a window into a different world, embedded inside a relational table. The moment you store one, you have left 1NF for that attribute, and the relational constraints no longer describe it.
There are methods to access that particular field — just as integer, float, and string are data types in the relational world, JSON is the data type in that world. Sometimes we use it, sometimes we don't — any time we give a key-value, we can define any new entry; there is not much requirement. It is a different world altogether.
3.10.2 Document Databases and the CAP Properties
Here we want to ensure that all the ACID properties — everything — is followed. (The spoken wording in the lecture came out as "asset properties"; the standard term for the relational transaction guarantees is ACID — atomicity, consistency, isolation, durability.) There, they talk only about either of the consistency, availability, and partition tolerance — the CAP properties — (the spoken wording was "CAS property"; the standard trade-off triangle for distributed databases is CAP — consistency, availability, partition tolerance) because in that world we talk only about the scalability aspect. Many industries are using some form of NoSQL because of the scalability aspects and other aspects. If you understand this particular purpose — how you store, how you retrieve — the small adjustments you have to do will be taught in this particular course later on, most likely if we have time, so that you can also understand this world as well.
Formalize: ACID versus CAP
ACID — the relational guarantee, enforced by the transaction system:
- Atomicity — either all operations of a transaction are reflected in the database, or none are.
- Consistency — a transaction run in isolation takes the database from one consistent state to another.
- Isolation — concurrent transactions appear to run one after another; each is unaware of the others.
- Durability — once a transaction commits, its changes persist even if the system fails.
CAP — the distributed trade-off. The CAP theorem says a distributed database can have at most two of these three properties:
- Consistency — every read sees the latest version; all live replicas agree.
- Availability — the system keeps answering reads and writes even when some nodes fail.
- Partition tolerance — the system keeps working when the network splits so that nodes cannot talk.
In any large-scale distributed system, partitions cannot be prevented, so either availability or consistency is sacrificed; many NoSQL systems accept weaker consistency in exchange for high availability and choose to converge later — the goal becomes eventual consistency rather than consistency at all times.
Scope: Which world is "right" depends on the workload. Relational systems buy ACID — and pay with the cost of joins, constraints, and fixed schemas. NoSQL systems buy scalability — and pay by losing or weakening those very guarantees: no automatic joins, no foreign keys, eventual consistency. The rule of thumb the industry uses: transactions and integrity first, choose relational; scale and flexible schemas first, consider document or key-value stores. And remember the professor's deeper point from 3.1: if you understand the process and the fundamentals — how you store, how you retrieve — plus one of the techniques, you can learn any storage model that an organization throws at you.
3.10.3 The XML Data Model: XSD Constructs
Between the rigid relational world of this session and the flexible document world of NoSQL sits a third, older semi-structured data model that the syllabus explicitly includes: XML (the Extensible Markup Language). XML documents are self-describing — the data carries its own structure as nested tags — which is why XML became the standard interchange format for industry: the same document can move between systems that share nothing but the format. An XML document is a tree: a root element, child elements, text content inside elements, and attributes attached to elements.
The schema of an XML document is defined with XSD — the XML Schema Definition language — and four constructs carry almost all of its expressive power:
xsd:elementdeclares an element. The element gets a name and a type; the type may be a built-in simple type (xsd:string,xsd:integer,xsd:date) or a user-defined type.xsd:complexTypedeclares an element that has structure — child elements and/or attributes — as opposed to asimpleTypeelement that holds only text. AcomplexTypeis the XML analog of a relation or a record: one element that contains several others.xsd:sequenceis the compositor inside acomplexTypethat fixes the order of the child elements: the children must appear in exactly the declared order. (The alternativesxsd:choice— exactly one of several — andxsd:all— any order, each at most once — complete the compositor family.)minOccursandmaxOccursset the cardinality of a child element inside acomplexType— the exact same (min, max) idea as the ER multiplicity notation of the earlier sessions. The defaults are1and1(exactly one, mandatory).minOccurs="0"makes the child optional;maxOccurs="unbounded"makes it a collection — the XML way of expressing "many."
A worked schema makes all four constructs land at once. The requirement: a course catalog in which a department offers zero or more courses, each course has a number, a title, and one or more instructors:
<xsd:element name="course">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="number" type="xsd:string"/>
<xsd:element name="title" type="xsd:string"/>
<xsd:element name="instructor" type="xsd:string"
minOccurs="1" maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:attribute name="code" type="xsd:string"/>
</xsd:complexType>
</xsd:element>
Read against the ER vocabulary: course is the entity; number, title, instructor are its attributes; the instructor element with minOccurs="1" maxOccurs="unbounded" is a multi-valued attribute with total participation — every course has at least one instructor, possibly many; and code is an XML attribute (metadata about the element) rather than a child. Every constraint of the earlier ER lectures — single-valued versus multi-valued, at least versus at most — has an XSD spelling. And the same reading transfers in the other direction: xsd:choice between two elements says "exactly one of these alternatives, like a discriminating attribute," and xsd:all says "these children may come in any order," which a relational table would never care about at all.
3.10.4 XML and Database Integration: Native XML vs Publishing
The syllabus's second XML topic is the two-way bridge between XML and relational databases: when the data lives in relations, how does it get out as XML — and when XML arrives, where does it live?
Publishing XML from relational databases. When the relational data is the source of truth, XML is produced on demand as an interchange format: a query extracts the tuples, and the engine formats them into a well-formed document. The mapping is the mirror of the ER-to-relational mapping of section 3.6: each relation becomes a complex element; each tuple becomes a child element under it; each attribute becomes either a child element or an XML attribute; and each foreign key reference becomes a nested child — the relational hierarchy is the XML hierarchy. Standard SQL has built-in support: the XML data type plus the XMLElement, XMLAttributes, and XMLAgg functions (the SQL/XML standard) compose relational results into documents, and XSLT transforms them into any presentation format. The advantages are total: the data keeps full relational query power, joins, transactions, and integrity; XML is produced only when something asks for it. The price is that a document spanning several joins must be assembled each time it is requested.
Native XML databases. When the document itself is the unit of work, the document is stored as-is in a native XML database — no table decomposition, no shredding into tuples; the engine stores the tree (often in B+-tree-indexed nodes, connecting to the indexing story of later sessions) and answers queries in XQuery, the query language for XML documents. Native XML preserves document order, comments, and structure exactly, and the document is stored and retrieved atomically — like a BLOB with structure. The price is that joins, integrity constraints, and the transactional guarantees of the relational model are weaker or absent, exactly the trade-off the session described for NoSQL documents. The practical rule: native XML when documents arrive whole and leave whole and their internal structure matters (medical records, legal filings, product feeds, configuration catalogs); publishing when XML is only a delivery format and the authoritative data must stay queryable as relations.
The connection to the session's own Postgres-JSON discussion is direct: JSON, BSON, and XML are three dialects of the same semi-structured idea, and the relational-vs-document tension described in 3.10.1–3.10.2 applies identically to XML — it was, in fact, the industry's first experience of that tension, a decade before NoSQL.
Real-world: XML is the interchange standard in finance (FIX, ISO 20022 messages), publishing (RSS feeds, DocBook), and government data exchange; SQL Server and Oracle both ship the XML data type with XQuery support, so the SQL/XML mapping above runs in production databases today.
3.10.5 Student Questions and Answers
Q: In the relational model we learn that the attribute should have only one value — we cannot store multiple values in the same attribute. But practically, in one implementation in Postgres in our organization, there is a data type called JSON which is given as one of the fields, and we actually store a set of key-value pairs in the same attribute. Is this kind of an exception, or maybe the implementation itself is something different?
A: First of all, I'd like to confess that I have not worked on Postgres. Secondly, there are different types of storage as well. What we are showing is a relational one. However, the key-value pair is a document database, generally — in a document database like Cassandra, we have a key-value pair, which is a NoSQL relation. NoSQL means the constraints for the relational model do not apply in that world. They generally use JSON, or binary BSON — the binary version of that — which can be MongoDB, another version of that. So the constraints that we are discussing here in the relational one would be differently applied in that one. Here we want to ensure that all the ACID properties are followed; there they talk only about either of the consistency, availability, and partition tolerance — the CAP properties — because in that world we talk only about the scalability aspect. Many of the industries are using some form of NoSQL because of the scalability aspects. If you understand this particular purpose — how you store, how you retrieve — the small adjustments will be taught in this particular course later on, most likely if we have time. In that world, the data type itself is a JSON; we store a set of key-value pairs there, and there are methods to access from that particular field. It is a different world altogether.
Recap + bridge: The relational model guarantees ACID; document and key-value worlds relax those constraints (and 1NF with them) in exchange for scalability, trading on the CAP triangle. JSON, BSON, and XML are three dialects of semi-structured data with the same publishing-or-native choice. This closes the arc that began in 3.1: requirement → ER diagram → relational schema → constraints — and the next sessions carry this schema into SQL, normalization, and beyond.
Exam Guidance Summary
The session's exam-relevant points, gathered in one place:
- The project and assignment are marked and carry weightage. At least basic feedback is expected; if feedback is missing along with the marks, you can reach out and arrange a one-to-one discussion of your assignment.
- The first quiz window runs from the 19th to the 28th of February — that is the first assessment deadline for the course, and note that it is a quiz, not the assignment. Keep it in mind if you have any questions about scheduling.
- The project is milestone-based in spirit: the expectation is a requirement specification first, then the ER diagram, then the relational model, then normalization and validation — and you may convert the same requirement into an ER diagram and then into a relational model as you progress. Submission at each milestone, with feedback at each milestone, is the preferred structure.
- Do not cram the ER-to-relational conversion rules: the primary key choice in a relationship relation follows from reasoning about the cardinality — which side can appear at most once. In a one-to-many relationship, the key is the many side; in a many-to-many, both keys together form the key. Understand why, and you will do it correctly every time.
- The four key concepts — super key, key, candidate key, and primary key — behave like a containment chain: the primary key is one of the candidate keys, the candidate keys are exactly the minimal super keys, and every super key is any unique combination. Do not cram the definitions; reason about the containment.
- The relational model fundamentals, including the domain of a relation, are the core of today's material — review the earlier session's material for the formal definitions, since today's session focuses on the practical application of the relational model.
- The different constraints — key constraints (entity integrity), referential integrity (foreign keys), domain constraints, and not-null constraints — plus the three delete options for foreign keys (restrict, cascade, set default; standard SQL adds set null) are the important conceptual pieces of this session.
- The distinction between degree and cardinality (3.5) is a frequent source of confusion: degree counts the participating entity types; cardinality describes one-to-one, one-to-many, many-to-one. In a ternary relationship, cardinality becomes genuinely ambiguous — which is exactly why designers avoid more than two participants.
- Labs are coming very soon and will expose you to the project work directly; keep the project going side by side.
Key Industry Applications
How today's session plays out in real organizations:
- Real-world: database management systems from Oracle to open sources like MySQL, and Microsoft SQL Server, all provide the four essential properties — data storage, abstraction, views, and concurrent sharing.
- Real-world: dynamic airline pricing at an international airline like Lufthansa — using geopolitics, demographics, World Cup, Olympics, and election data to plan pricing a year ahead — is a requirement-specification problem for database designers. The requirement talk you heard in 3.2 is exactly how such systems begin.
- Real-world: data scientists in industry spend a major part of their effort on the primary data — which data to rely upon and how to get it — not just on AI and ML models.
- Real-world: data as the new oil — using stored data to give customers a customized, tailor-made, "wow" experience instead of treating a product like a commodity.
- Real-world: ER diagrams are drawn with pen and paper, draw.io, or PowerPoint in practice; MindMap was used only as a teaching aid, not as a modeling standard.
- Real-world: generative AI tools (like GPT) are used in coursework and industry — use them to make tasks easier and to learn, but never to offload the thinking; AI-generated plagiarism is still plagiarism.
- Real-world: SQLite and other open-source SQL engines are interchangeable for course projects — "mostly all of them are the same."
- Real-world: government and public-sector models — for example, an employee who works in one school and also in another school on deputation — show that the requirement specification drives the diagram; the same model changes with different requirements.
- Real-world: NoSQL and document databases — Cassandra (key-value), MongoDB (BSON), and graph stores like Neo4j — relax the relational constraints in exchange for scalability; relational systems follow ACID properties while distributed systems talk about the CAP properties (consistency, availability, partition tolerance).
- Real-world: Postgres offers a JSON data type, which stores key-value pairs inside a single attribute — an example of how implementations blend worlds; understand the process and fundamentals, and you can learn any storage model quickly.
- Real-world: XML remains the interchange standard in finance (FIX, ISO 20022 messages), publishing (RSS feeds, DocBook), and government data exchange; SQL Server and Oracle ship the XML data type with XQuery support, so the SQL/XML publishing path runs in production databases today.
DDA Lecture 3 notes · From Requirements to the Relational Model
Sections Breakdown
Why databases exist — the four essential properties (store, abstraction, views, concurrent sharing) — plus the project assignment, milestones, and the professor's guidance on tools, AI use, and feedback.
Where design begins: the Lufthansa dynamic-pricing requirement, the university schema interview, pertinent plain-language questions, the room analogy, and the end-to-end requirement-to-schema process.
The ER vocabulary — entities, attributes, relationships, degree — with weak entities, owner entities, the identifying relationship (double rhombus), and reading arrows and double lines.
The four key concepts — super key, key, candidate key, primary key — as a containment chain, with a first look at the foreign key and the section-relation worked example.
The extended ER model: ternary (n-ary) relationships as irreducible associations, the degree-versus-cardinality distinction, arrow ambiguity, and categories (union types) such as OWNER.
Converting the ER diagram into a relational schema: entity-to-relation rules, multivalued attributes, relationship relations with keys from both sides, and reducing redundant relations.
Codd's relational model: everything is a relation — schemas and states, tuples, attributes, domains, first normal form, and set semantics (no ordering, no duplicates).
The three layers of constraints (implicit, schema-based, application-based) and the four integrity families: key/entity integrity, referential integrity, domain, and not-null.
Referential integrity in depth: the WORKS_ON example, the delete options (restrict, cascade, set default, set null), and self-referencing foreign keys like SUPER_SSN referencing SSN.
Relational versus document worlds: the Postgres JSON question, ACID versus CAP, and the XML data model (XSD constructs, publishing versus native XML databases).
The professor's exam-relevant guidance for this session: project milestones, quizzes, key reasoning rules, and the important conceptual pieces.
How the session plays out in real organizations: airline pricing, data science, ER tools, NoSQL in production, and XML as an interchange standard.
Exam Revision Notes
Below is the distilled, exam-ready core. Every entry comes from the full explanation above. Use this section for rapid review; return to the main notes when a point needs more context.
Course Journey and the Project
Must-know: A database management application has four essential properties: store the data, provide abstraction, maintain views for different applications, and share data concurrently. The project flows requirement -> ER diagram -> relational schema -> normalization.
⚠️ Top pitfall: Going by the tools (draw.io, PowerPoint, MindMap) instead of first understanding what to store, why, and how; tools only represent the picture.
Self-check: Name the four essential properties of any database management application.
Connects to: Customer Requirement Specification (3.2).
Customer Requirement Specification
Must-know: The process is one line: user gives the requirement, the designer asks pertinent questions in plain language, converts it into an ER diagram, the client confirms it, and it becomes a relational schema for storage and retrieval.
⚠️ Top pitfall: Asking the client database vocabulary too early (what are the constraints?) makes the user go blank; ask how things are related instead.
Self-check: Why does the designer ask 'how are students and instructors related?' rather than 'what are the constraints between section and department?'
Connects to: Course Journey and the Project (3.1); ER Model Recap: Entities, Relationships, Weak Entities (3.3).
ER Model Recap: Entities, Relationships, Weak Entities
Must-know: Arrow = at most one; no arrow = many; double line = total participation. A weak entity's full key is owner's key + partial key; its identifying relationship is a double rhombus and always total participation.
⚠️ Top pitfall: Thinking a weak entity has no key at all - it has no key by itself, but owner key + partial key (course_id, sec_id, semester, year for section) makes it fully identifiable.
Self-check: How is the weak entity section distinguished when two sections look identical by their own attributes?
Connects to: Customer Requirement Specification (3.2); Keys: Super Key, Key, Candidate Key, Primary Key (3.4); From ER Diagram to Relational Schema (3.6).
Keys: Super Key, Key, Candidate Key, Primary Key
Must-know: Containment: primary key is one candidate key; candidate keys are exactly the minimal super keys; super keys are all unique combinations. Minimal means dropping any attribute destroys uniqueness, not that the key is smallest in size.
K - {A} not a superkey for every A in K
⚠️ Top pitfall: Adding a redundant attribute to a key makes it only a super key; confusing foreign key with super key.
Self-check: Why is {course_id, sec_id, semester, year, building} a super key but not a key for section?
Connects to: ER Model Recap: Entities, Relationships, Weak Entities (3.3); From ER Diagram to Relational Schema (3.6); The Foreign Key Constraint in Detail (3.9).
The Extended ER Model: Ternary Relationships
Must-know: Degree = how many entity types participate (binary, ternary); cardinality = 1:1, 1:N, M:N. A ternary cardinality is ambiguous as soon as a 'one' appears, so designers avoid more than two participants. A category is a subset of the union of different-typed superclasses: T subset D1 union D2 union ... union Dn.
⚠️ Top pitfall: Splitting a ternary relationship into binary pairs loses the triple constraint; reading two arrows out of a non-binary relationship is ambiguous.
Self-check: Why does 'one student' in a project-guide ternary relationship make the diagram ambiguous?
Connects to: ER Model Recap: Entities, Relationships, Weak Entities (3.3); Keys: Super Key, Key, Candidate Key, Primary Key (3.4); From ER Diagram to Relational Schema (3.6).
From ER Diagram to Relational Schema
Must-know: The primary key of a relationship relation follows from 'which side can appear at most once': 1:N puts the key on the many side (advisor key is s_ID); M:N makes the combination of both keys the key (teaches, takes). The identifying relationship of a weak entity is redundant and reduced into one table.
takes(ID, course_id, sec_id, semester, year, grade) with PK {ID, course_id, sec_id, semester, year}; grade is not part of the key
⚠️ Top pitfall: Cramming rules instead of reasoning; forgetting that in a 1:N relationship the 'many' side key is the primary key because it appears at most once.
Self-check: Why is the primary key of the advisor relation just s_ID and not (s_ID, i_ID)?
Connects to: Keys: Super Key, Key, Candidate Key, Primary Key (3.4); The Extended ER Model: Ternary Relationships (3.5); The Relational Model (3.7).
The Relational Model
Must-know: A relation is a set of tuples: no ordering across tuples or attributes and no duplicate records. 1NF (atomic values only) is implicit in the relational model. Schema = definition; state = populated content. Degree counts fields, cardinality counts tuples.
r(R) = { t_1, ..., t_m } with t_i = (v_{i1}, ..., v_{in}), v_{ij} in D_j
⚠️ Top pitfall: Treating table and relation as identical: tables allow duplicates and ordering; relations forbid both.
Self-check: What two properties of a relation make it different from a table?
Connects to: From ER Diagram to Relational Schema (3.6); Relational Constraints (3.8).
Relational Constraints
Must-know: Three layers: implicit (no duplicate tuples, 1NF), explicit (primary key, not-null, foreign key written in the schema), application-based (manager salary rules, checked in programs). Entity integrity: no primary key value can be NULL. Domain constraints keep values in their domain (SSN cannot be 'Amitua').
⚠️ Top pitfall: Mixing the layers: expecting the DBMS to enforce application-based business rules it was never told about, or allowing NULL into a primary key.
Self-check: In a banking schema with account number as primary key, may the user name be NULL?
Connects to: Keys: Super Key, Key, Candidate Key, Primary Key (3.4); The Foreign Key Constraint in Detail (3.9).
The Foreign Key Constraint in Detail
Must-know: A foreign key says every referencing value must exist in the referenced relation (referential integrity). Delete options: restrict (reject), cascade (propagate), set default (must exist in the referenced table), set null (nullable FK only). The foreign key may reference its own relation: SUPER_SSN stores the manager, who must be an employee.
WORKS_ON(Essn, Pno, Hours), PK {Essn, Pno}, FK Pno references PROJECT(Pnumber)
⚠️ Top pitfall: Calling the foreign key 'the relationship between tables' (it is its own concept) or thinking SUPER_SSN is a replica of SSN (its purpose is that the entry must exist).
Self-check: Why must a SET DEFAULT value exist in the referenced table?
Connects to: Keys: Super Key, Key, Candidate Key, Primary Key (3.4); Relational Constraints (3.8).
Relational versus NoSQL and Document Databases
Must-know: Relational systems guarantee ACID (atomicity, consistency, isolation, durability); distributed/NoSQL systems trade on CAP (consistency, availability, partition tolerance - at most two of three) for scalability. A JSON column stores key-value pairs in one attribute - the document world's data type, with different constraints.
⚠️ Top pitfall: Reading a JSON field in Postgres as a violation of 1NF: it is not an exception but a different (document) world embedded in a relational product, with different constraints.
Self-check: What are the three CAP properties, and why can a distributed system have only two of them?
Connects to: The Relational Model (3.7); Relational Constraints (3.8).
Exam Guidance Summary
Must-know: Reason, do not cram: the primary key of a relationship relation follows from which side appears at most once; constraints (entity integrity, referential integrity, domain, not-null) and the foreign key delete options (restrict, cascade, set default) are the important conceptual pieces.
⚠️ Top pitfall: Memorizing conversion rules instead of deriving the primary key from the cardinality.
Self-check: When does a foreign key delete option become SET DEFAULT invalid?
Connects to: Course Journey and the Project (3.1); From ER Diagram to Relational Schema (3.6); Relational Constraints (3.8); The Foreign Key Constraint in Detail (3.9).
Key Industry Applications
Must-know: Relational systems follow ACID; distributed systems trade on CAP (consistency, availability, partition tolerance) for scalability; JSON, BSON and XML are dialects of the same semi-structured idea.
⚠️ Top pitfall: Assuming one storage model fits all organizations; fundamentals and one technique let you learn any model (Cassandra, MongoDB, Neo4j, Postgres JSON).
Self-check: Which real products represent key-value, document, and graph storage?
Connects to: Course Journey and the Project (3.1); Relational versus NoSQL and Document Databases (3.10).
Was this lecture useful?
BitsNotes AI Assistant
Subject Notes AssistantConfigure AI Chat
Choose how to access the chatbotSigned in as
Powered by BitsNotes — 20 messages per day. No API key needed. Want unlimited access? Use "Bring Your Own Key" mode.
Sign in to use AI Chat
Get 20 free AI messages per day to ask questions about your lecture notes. Sign in with Google or GitHub — it takes 5 seconds.
Sign In to BitsNotesSwitch to "Bring Your Own Key" tab above for unlimited access with any OpenAI-compatible provider.