Dbms q-a
Dbms q-a
Subqueries:
1. Employees with Salary Above Average:
○ Question: Write an SQL query to find the names of all employees whose salary is
above the average salary of all employees.
○ Answer:
SELECT name
FROM employees
WHERE salary > (SELECT AVG(salary) FROM employees);
Views:
1. Creating a View:
○ Question: Create a view named high_salary_employees that contains the names
and salaries of all employees who earn more than $75,000.
○ Answer:
CREATE VIEW high_salary_employees AS
SELECT name, salary
FROM employees
WHERE salary > 75000;
Theory Questions
1. Define data independence and explain its significance in database systems.
○ Answer: Data independence refers to the ability to change the database schema
(structure) without affecting the application programs that access the data. This is
crucial because it allows for flexibility and easier maintenance of the database.
2. What are the different types of data models? Briefly describe each.
○ Answer:
■ Hierarchical Model: Represents data as a tree-like structure with
parent-child relationships.
■ Network Model: More flexible than hierarchical, allowing for multiple
parent-child relationships.
■ Relational Model: Represents data in tables with rows and columns, the
most widely used model today.
■ Object-Oriented Model: Represents data as objects with attributes and
methods.
■ NoSQL Models: A broad category of database systems that don't rely on the
traditional relational model, offering flexibility and scalability.
3. Explain the concept of a database schema and its importance.
○ Answer: A database schema is a logical blueprint or plan of the database structure.
It defines the tables, columns, data types, relationships, and constraints within the
database. The schema is crucial for understanding and designing the database,
ensuring data integrity, and facilitating efficient data retrieval.
4. What is the role of a Database Administrator (DBA)?
○ Answer: A DBA is responsible for managing the database system, including tasks
such as:
■ Designing and implementing the database schema
■ Ensuring data security and integrity
■ Monitoring database performance
■ Backing up and recovering data
■ Granting and managing user access
■ Troubleshooting database issues
5. What are the key components of an Entity-Relationship Diagram (ERD)?
○ Answer: Key components of an ERD include:
■ Entities: Objects or concepts that you want to store information about.
■ Attributes: Properties or characteristics of entities.
■ Relationships: Associations between two or more entities.
■ Cardinality: The number of instances of one entity that can be associated
with instances of another entity.
6. Explain the concept of a weak entity and its relationship with a strong entity.
○ Answer:
■ Weak Entity: An entity that cannot exist independently and depends on
another entity (strong entity) for its existence.
■ Strong Entity: An entity that can exist independently and does not depend
on any other entity.
7. What are the different types of cardinality constraints in an ERD?
○ Answer:
■ One-to-one
■ One-to-many
■ Many-to-one
■ Many-to-many
8. How do you represent a many-to-many relationship in an ERD?
○ Answer: By creating an additional entity (called a junction or association entity) to
link the two entities involved in the many-to-many relationship.
9. Define a relation in the context of the relational model.
○ Answer: A relation is a two-dimensional table with rows and columns. Each row
represents a tuple (record) and each column represents an attribute.
10.Explain the concept of functional dependency and its importance in database
design.
○ Answer: A functional dependency is a relationship between two attributes or sets of
attributes where the value of one determines the value of the other. Functional
dependencies are crucial in database design because