DBMS-2 Relational Model-1
DBMS-2 Relational Model-1
Top Relational Databases Interview Questions and Answers You Should Learn (interviewkickstart.com)
● Informally, each relation resembles a table of values or, to some extent, a flat file of records.
● It is called a flat file because each record has a simple linear or flat structure.
When a relation is thought of as a table of values, each row in the table represents a collection of related
data values.
A row represents a fact that typically corresponds to a real-world entity or relationship.
In the formal relational model terminology, a row is called a tuple, a column header is called an attribute, and
the table is called a relation. The data type describing the types of values that can appear in each column is
represented by a domain of possible values.
Chatgpt
The relational data model is a conceptual model used to organize data into a structure of tables
(relations) consisting of rows (tuples) and columns (attributes).
Tables (Relations): Tables are the basic building blocks of the relational model. They consist of rows and
columns, where each row represents a record, and each column represents an attribute of that record.
Attributes (Fields): Attributes define the properties of the data stored in a table. Each column in a table
corresponds to an attribute, such as a person's name, age, or address.
Tuples (Rows): Tuples are individual records in a table. Each tuple represents a single instance of the entity
being modeled and contains values for each attribute defined in the table's schema.
Keys: Keys are used to uniquely identify tuples within a table. The primary key is a special type of key that
uniquely identifies each tuple in the table. Other types of keys include candidate keys and foreign keys.
Relationships: Relationships define associations between tables. These relationships are typically established
through keys, where the value of a key in one table corresponds to the value of a key in another table.
Constraints
Relational database constraints are rules that enforce data integrity and consistency within a relational
database. These constraints are used to maintain the accuracy and validity of the data stored in the
database. Some common relational database constraints include:
Primary Key Constraint: This constraint ensures that the values in a specified column (or columns) are
unique and not null. It uniquely identifies each tuple in a table.
Foreign Key Constraint: This constraint establishes a relationship between two tables by enforcing referential
integrity. It ensures that values in a column (or columns) of one table match values in another table's primary key
or unique key column(s).
Unique Constraint: This constraint ensures that all values in a specified column (or columns) are unique,
except for null values.
Check Constraint: This constraint enforces a condition that must be true for every tuple in a table. It is used to
enforce business rules or data integrity rules.
Not Null Constraint: This constraint ensures that a column does not contain null values.
These constraints help to maintain the consistency and integrity of data within a relational database, ensuring
that the data remains accurate and reliable.
Data integrity and consistency are crucial aspects of maintaining the quality and reliability of data within a
database:
Data Integrity:
Data integrity refers to the accuracy, completeness, and reliability of data stored in a database. It ensures that
the data accurately represents the real-world entities and relationships it is meant to model. There are several
aspects to data integrity:
● Entity Integrity: This ensures that each record (tuple) within a table is uniquely identifiable. Typically, this
is enforced using primary key constraints, which ensure that each tuple has a unique identifier.
● Referential Integrity: This ensures the consistency of relationships between tables. Referential integrity
is maintained by foreign key constraints, which ensure that values in a column (or columns) of one table
match values in another table's primary key or unique key column(s).
● Domain Integrity: This ensures that data values stored in the database meet certain predefined criteria
or rules. This can be enforced through data type constraints, check constraints, and other validation rules.
● User-defined Integrity: This refers to any additional integrity rules or constraints that are specific to the
business logic or requirements of the database application.
Data Consistency:
Data consistency refers to the correctness and reliability of data across the entire database. It ensures that data
is accurate and up-to-date and that it reflects the latest changes made to the database. Data consistency is
maintained through various means:
● Concurrency Control: In multi-user database environments, concurrency control mechanisms are used
to manage simultaneous access to data by multiple users or processes. These mechanisms prevent
conflicts and ensure that data remains consistent despite concurrent transactions.
● Database Constraints: Constraints such as primary key, foreign key, unique, and check constraints
enforce data integrity rules, which in turn help maintain data consistency by preventing invalid or
inconsistent data from being entered into the database.
● Data Validation and Cleansing: Regular validation and cleansing processes can help identify and
correct inconsistencies or errors in the data, ensuring that it remains consistent and accurate over time.
Overall, data integrity and consistency are essential for ensuring that a database provides reliable, accurate, and
trustworthy information to support critical business processes and decision-making.
3.1 Domains, Attributes, Tuples, and Relations
A domain D is a set of atomic values. By atomic we mean that each value in the domain is indivisible as far as
the formal relational model is concerned.
A common method of specifying a domain is to specify a data type from which the data values forming the
domain are drawn.
■ Usa_phone_numbers. The set of ten-digit phone numbers valid in the United States.
A relation of degree seven, which stores information about university students, would contain seven attributes
describing each student. as follows: STUDENT(Name, Ssn, Home_phone, Address, Office_phone, Age, Gpa)
A relation (or relation state) r of the relation schema R(A1, A2, ..., An), also denoted by r(R), is a set of
n-tuples r = {t1, t2, ..., tm}. Each n-tuple t is an ordered list of n values t =<v1,v2,v3,...vn>
The earlier definition of a relation can be restated more formally using set theory concepts as follows. A
relation (or relation state) r(R) is a mathematical relation of degree n on the domains dom(A1), dom(A2), ...,
dom(An), which is a subset of the Cartesian product (denoted by ×) of the domains that define R:
r(R) ⊆ (dom(A1) × dom(A2) × ... × dom(An))
It is possible for several attributes to have the same domain. The attribute names indicate different roles, or
interpretations, for the domain. For example, in the STUDENT relation, the same domain
USA_phone_numbers plays the role of Home_phone, referring to the home phone of a student, and the
role of Office_phone, referring to the office phone of the student. A third possible attribute (not shown) with
the same domain could be Mobile_phone.
● Values and NULLs in the Tuples. Composite and multivalued attributes are not allowed. This model is
sometimes called the flat relational model.
Multivalued attributes must be represented by separate relations, and composite attributes are represented
only by their simple component attributes in the basic relational model.
● We can have several meanings for NULL values, such as value unknown, value exists but is not
available, or attribute does not apply to this tuple (also known as value undefined).
The exact meaning of a NULL value governs how it fares during arithmetic aggregations or
comparisons with other values.
For example, a comparison of two NULL values leads to ambiguities—if both Customer A and B
have NULL addresses, it does not mean they have the same address.
3.2 Relational Model Constraints and Relational Database Schemas
1. Constraints that are inherent in the data model. We call these inherent model-based constraints or
implicit constraints.( refer to the restrictions or rules that are inherent in the data model itself.)
They are derived from the rules of the miniworld that the database represents.
Examples:
3. Constraints that cannot be directly expressed in the schemas of the data model, and hence must be
expressed and enforced by the application programs. We call these application-based or semantic
constraints or business rules.
Examples:
domain constraints,
key constraints,
constraints on NULLs,
entity integrity constraints,
referential integrity constraints.
The data types associated with domains typically include standard numeric data types
● for integers (such as short integer, integer, and long integer)
● and real numbers (float and double precision float).
● Characters, Booleans, fixed-length strings, and variable-length strings are also available,
● as are date, time, timestamp, and money, or other special data types.
EID Name Phone
01 Anuj 9696406570
02 Shivam 8871253247
01 Akash 3245698710 (Violation: Composite
attribute "Name")
● Suppose that we denote one such subset of attributes by SK; then for any two distinct tuples t1 and t2 in
a relation state r of R, we have the constraint that: t1[SK]≠ t2[SK]
Any such set of attributes SK is called a superkey of the relation schema R.
● A superkey SK specifies a uniqueness constraint that no two distinct tuples in any state r of R can have
the same value for SK.
● Every relation has at least one default super key—the set of all its attributes.
● A superkey can have redundant attributes, however, so a more useful concept is that of a key, which has
no redundancy. A key K of a relation schema R is a superkey of R with the additional property that
removing any attribute A from K leaves a set of attributes K that is not a superkey of R any more. Hence, a
key satisfies two properties:
1. Two distinct tuples in any state of the relation cannot have identical values for (all) the attributes in
the key. This first property also applies to a superkey.
2. It is a minimal superkey—that is, a superkey from which we cannot remove any attributes and still
have the uniqueness constraint in condition hold. This property is not required by a superkey.
Whereas the first property applies to both keys and superkeys, the second property is required only for keys.
Hence, a key is also a superkey but not vice versa.
In general, any superkey formed from a single attribute is also a key. A key with multiple attributes must
require all its attributes together to have the uniqueness property.
A relation schema may have more than one key.In this case, each of the keys is called a candidate key.
For example, the CAR relation has two candidate keys: License_number and Engine_serial_number.
It is common to designate one of the candidate keys as the primary key of the relation.
We use the convention that the attributes that form the primary key of a relation schema are underlined.
Questions:
1. What are the three core features of an RDBMS, and what do each of them represent?
○ The three main features are:
■ Name: Represents the specific name for each relation (table) in the database.
■ Attributes: Refer to each column in a relation.
■ Tuples: Correspond to the rows in the relation1.
2. What are the four types of keys in an RDBMS?
○ The key types are:
■ Primary Key: Uniquely identifies each tuple in a relation.
■ Candidate Key: Alternative keys that could serve as the primary key.
■ Foreign Key: Establishes relationships between tables by referencing primary keys from other tables.
■ Super Key: A set of one or more attributes that uniquely identify tuples1.
3. What is an index, and what are the different types of indexes?
○ Indexes are methods to enhance table performance for faster record retrieval.
○ The three types of indexes are:
■ Unique Index: Ensures uniqueness of values in a column.
■ Clustered Index: Determines the physical order of data rows in a table.
■ Non-Clustered Index: Provides a separate structure for faster data access1.
4. What is a buffer manager, and what are its primary responsibilities?
○ A buffer manager is a module that collects data from storage disks.
○ It determines which data to cache in memory to increase processing speeds1.
5. Explain the relational database model.
○ The relational model defines the relationship among various databases and their connections.
○ It represents how data is stored using tables (relations) with rows (tuples) and columns (attributes)2.
6. What is the difference between a primary key and a unique key?
○ Primary Key: It uniquely identifies each tuple in a relation. There can be only one primary key per table, and it cannot
contain NULL values.
○ Unique Key: It ensures uniqueness but allows NULL values. A table can have multiple unique keys.
7. Explain the concept of referential integrity.
○ Referential integrity ensures that relationships between tables are maintained. When a foreign key references a
primary key, it must match an existing value in the referenced table.
8. What is the purpose of the CHECK constraint?
○ The CHECK constraint restricts the values that can be inserted into a column based on a specified condition. For
example, you can use it to enforce age limits or valid date ranges.
9. Describe the difference between a candidate key and a super key.
○ Candidate Key: It is a minimal super key (i.e., a set of attributes that uniquely identifies tuples). It can be chosen as
the primary key.
○ Super Key: It is any set of attributes that uniquely identifies tuples, including the candidate key.
10. How does normalization improve database design?
○ Normalization reduces data redundancy and ensures efficient storage by organizing data into separate tables. It
minimizes anomalies and maintains data integrity.