Dbms interview
Dbms interview
Discuss the
different types.
Ans:
An integrity constraint is a rule that restricts the values allowed in a
database. It ensures the accuracy and consistency of data stored in the
database. There are several types of integrity constraints:
**Stored Attribute**: A stored attribute is an attribute whose value is directly stored in the
database. It's typically a piece of information that is directly provided and maintained within a
database table. For example, in a "Student" table, attributes like "StudentID," "Name," and
"DateOfBirth" would be stored attributes because their values are directly entered and stored
in the database.
For example, consider two tables: "Orders" and "Customers." The "Orders" table has a
foreign key attribute called "CustomerID," which references the primary key attribute
"CustomerID" in the "Customers" table. The referential integrity constraint ensures that every
value in the "CustomerID" column of the "Orders" table must exist in the "CustomerID"
column of the "Customers" table. This constraint prevents orphaned records and maintains
the integrity of the relationship between orders and customers. If a customer record is
deleted, the referential integrity constraint might dictate that associated order records be
deleted as well, or that the deletion be restricted until associated orders are handled
appropriately.
**Data Abstraction**:
Data abstraction is the process of hiding certain details and showing only essential
information to the user. It helps in managing complexity by allowing users to focus on
relevant aspects of data while ignoring unnecessary details. There are three levels of data
abstraction:
- **Physical Level**: This is the lowest level of abstraction, which describes how data is
stored in the database system. It includes details such as data storage, data types, indexing
methods, etc.
- **Logical Level**: This level describes what data is stored in the database and the
relationships among the data. It hides the physical storage details and focuses on the logical
structure of the data.
- **View Level**: This is the highest level of abstraction, which represents a part or subset
of the database from the user's perspective. It provides different views of the database to
different users based on their requirements, without exposing the entire database schema.
**Normalization of Relations**:
Normalization is the process of organizing the attributes and tables of a relational database
to minimize redundancy and dependency. It helps in avoiding anomalies such as insertion,
deletion, and update anomalies, which can occur due to redundant data storage.
Anomalies include:
- **Insertion Anomaly**: Difficulty in adding data to the database due to the absence of
other related data.
- **Deletion Anomaly**: Unintentional loss of data while deleting information not intended
to be deleted.
- **Update Anomaly**: Inconsistency that occurs when updating data in one place but not
in others
10.Explain with example: super key, candidate key and primary key.
- **Super Key**: A super key is a set of attributes that uniquely identifies each tuple (row)
within a relation (table). It may contain more attributes than necessary to uniquely identify
tuples. For example, in a "Person" table, {PersonID, SocialSecurityNumber} could be a
super key.
- **Candidate Key**: A candidate key is a minimal super key, meaning it is a super key
with no unnecessary attributes. It uniquely identifies each tuple within a relation. In other
words, removing any attribute from a candidate key would cause it to lose its uniqueness
property. For example, in the "Person" table, if both PersonID and SocialSecurityNumber
uniquely identify each person, then both are candidate keys.
- **Primary Key**: The primary key is a candidate key chosen by the database designer to
uniquely identify tuples within a relation. It is used to enforce entity integrity and serve as the
main reference point for accessing and retrieving data from the table. In the "Person" table,
the database designer might choose PersonID as the primary key.