Dbms Question Bank
Dbms Question Bank
- **Data**: Raw facts and figures without context, such as numbers, text, or images.
- **Information**: Processed or organized data that is meaningful and useful for decision-
making.
- **DBMS** is needed to efficiently manage large volumes of data, ensure data integrity,
provide secure access, support concurrent data operations, and reduce data redundancy.
- **Advantages**: Improved data sharing, data security, data integrity, reduced data
redundancy, and better data management.
- **Schema**: The structure of the database, including tables, fields, relationships, and
constraints. For example, a university database schema might include tables for students,
courses, and enrollments.
- **Instance**: The actual data in the database at a given point in time. For example, a
student named John Doe enrolled in a course is an instance of the data in the students and
enrollments tables.
- **Three-layer architecture**:
- **External Level**: User views of the database, tailored to different user requirements.
- **Conceptual Level**: The logical view of the entire database, defining the structure
and relationships between data.
- **Internal Level**: The physical storage of data, including indexing and data access
methods.
- **1-Tier Architecture**: The database and application are on the same system. Example:
A standalone database application on a desktop.
- **2-Tier Architecture**: The client (application) communicates directly with the server
(database). Example: A desktop application connecting to a remote database server.
- **3-Tier Architecture**: Includes a middle layer (application server) between the client
and the database. Example: A web application where the web server interacts with the
database server on behalf of the client.
```
1-Tier:
[Application + Database]
2-Tier:
```
- **End Users**: Regular users who interact with the database through applications, such
as business analysts or customers.
- **Developers**: Create and maintain applications that interact with the database,
including designing and querying databases.
6. **What is data independence? Explain the difference between physical and logical data
independence with examples.**
- **Data Independence**: The ability to change the database schema at one level without
affecting the schema at other levels.
```sql
SELECT * FROM Employees
WHERE (Department = 'Sales' AND Salary > 50000)
OR (Department = 'Marketing' AND Salary > 60000);
```
This query retrieves employees who are either in the 'Sales' department with a
salary above 50,000 or in the 'Marketing' department with a salary above 60,000.
```sql
SELECT * FROM Products
WHERE Price BETWEEN 10 AND 50;
```
This query retrieves products with a price ranging from 10 to 50.
3. **Aggregate Functions in SQL:**
Aggregate functions perform a calculation on a set of values and return a single
value. Common aggregate functions include:
Example:
```sql
SELECT Department, AVG(Salary) AS AverageSalary
FROM Employees
GROUP BY Department;
```
This query calculates the average salary for each department.
Example:
```sql
SELECT CONCAT(FirstName, ' ', LastName) AS FullName
FROM Employees;
```
This query concatenates the first and last names of employees into a single full
name.
5. **What is SQL? Discuss the Different Languages of SQL and Its Commands:**
SQL (Structured Query Language) is a standard language for managing and
manipulating relational databases. It allows users to create, read, update, and delete
data within a database. SQL is divided into several sub-languages:
Given relations:
- `Supplier (S#, sname, status, city)`
- `Parts (P#, pname, color, weight, city)`
- `SP (S#, P#, quantity)`
a. SQL Queries:
**23. Define Data Models and Enlist the Different Data Models.**
- **Data Models**: Data models define how data is connected, stored, and
accessed. They provide a conceptual framework for organizing and managing data.
Data models abstract and simplify complex data structures to make it easier for
users to understand and manipulate the data.
The **Relational Data Model** organizes data into tables (relations), each with
rows (tuples) and columns (attributes). Tables can be linked using keys, such as
primary and foreign keys, which ensure that relationships between tables are
consistent. This model emphasizes data integrity and flexibility, allowing users to
query and manipulate data using a high-level query language like SQL. The
relational model supports operations such as selection, projection, and join, making
it a powerful tool for managing and analyzing data.
- **Hierarchical Model**:
- **Structure**: Tree-like hierarchy with a single parent-child relationship.
- **Relationships**: One-to-many relationships.
- **Flexibility**: Limited; rigid structure.
- **Complexity**: Higher complexity for retrieval due to hierarchical navigation.
- **Network Model**:
- **Structure**: Graph-like structure with multiple parent-child relationships.
- **Relationships**: Many-to-many relationships are supported.
- **Flexibility**: Greater than hierarchical model.
- **Complexity**: More complex relationships and data retrieval compared to
hierarchical.
- **Relational Model**:
- **Structure**: Data is organized into tables with rows and columns.
- **Relationships**: Supports one-to-one, one-to-many, and many-to-many
relationships through foreign keys.
- **Flexibility**: Highly flexible; changes in data structure do not require
reorganization of the database.
- **Complexity**: Simplifies data management and retrieval through SQL.
**Mapping Cardinalities** describe the number of instances of one entity that can
or must be associated with each instance of another entity. There are several types:
- **Entities**:
- **Student**: Attributes - Student_ID (PK), Name, Date_of_Birth, Email
- **Course**: Attributes - Course_ID (PK), Course_Name, Credits
- **Faculty**: Attributes - Faculty_ID (PK), Name, Department, Email
- **Department**: Attributes - Department_ID (PK), Department_Name,
Building
- **Relationships**:
- **Enroll** (between Student and Course): Many-to-Many (Students can enroll
in many courses, and each course can have many students)
- **Teaches** (between Faculty and Course): One-to-Many (A faculty can teach
many courses, but each course is taught by one faculty)
- **Belongs_to** (between Course and Department): Many-to-One (A course
belongs to one department, but a department can have multiple courses)
- **Cardinalities**:
- **Enroll**: Student (N) to Course (M)
- **Teaches**: Faculty (1) to Course (N)
- **Belongs_to**: Course (N) to Department (1)
The E-R diagram will include entities with their attributes and relationships with
their cardinalities, making it a comprehensive representation of the Parul
University database system.
**Unit 4**
**Short Questions:**
34. **Define the NOT NULL constraint and give an example of its use.**
- The NOT NULL constraint ensures that a column cannot have NULL values.
This is used to ensure that a column always has a value and cannot be left empty.
- **Example:** `CREATE TABLE Employees (EmployeeID INT NOT NULL,
Name VARCHAR(100) NOT NULL, Department VARCHAR(50));`
37. **What are aggregate functions in SQL and give examples of their usage?**
- Aggregate functions perform a calculation on a set of values and return a single
value. Common aggregate functions include:
- `COUNT(column_name)` - Counts the number of rows.
- `SUM(column_name)` - Adds up the values in a column.
- `AVG(column_name)` - Calculates the average value of a column.
- `MAX(column_name)` - Finds the maximum value in a column.
- `MIN(column_name)` - Finds the minimum value in a column.
- **Example:** `SELECT AVG(salary) FROM Employees;`
38. **What is the relational data model and how does it organize data?**
- The relational data model organizes data into tables (relations), each consisting
of rows (tuples) and columns (attributes). Each table represents an entity, with
columns representing attributes and rows representing records of that entity.
Relationships between tables are established through primary and foreign keys.
41. **Describe how the JOIN operation works in relational algebra. Provide
examples of different types of joins and when each is useful.**
- The JOIN operation combines rows from two or more tables based on a related
column.
- **Inner Join**: Combines rows from both tables that satisfy the join
condition.
- **Example:** `R1 ⨝ R2` where `R1` and `R2` are two relations and the join
condition is specified.
- **Left Outer Join**: Includes all rows from the left table and matching rows
from the right table; rows from the left table with no match in the right table will
have NULL values for right table columns.
- **Example:** `R1 ⟕ R2`
- **Right Outer Join**: Includes all rows from the right table and matching
rows from the left table; rows from the right table with no match in the left table
will have NULL values for left table columns.
- **Example:** `R1 ⟖ R2`
- **Full Outer Join**: Includes rows when there is a match in one of the tables.
- **Example:** `R1 ⟗ R2`
- **Cross Join**: Returns the Cartesian product of the two tables.
- **Example:** `R1 × R2`
45. **What is database schema? Explain the select, project, natural join, union, and
Cartesian product operations.**
- **Database Schema**: The structure of a database described in a formal
language, including tables, columns, and relationships.
- **Select (σ)**: Filters rows based on a condition.
- **Example:** `σ (Salary > 50000) (Employees)`
- **Project (π)**: Retrieves specific columns from a table.
- **Example:** `π (Name, Department) (Employees)`
- **Natural Join (⨝)**: Joins tables based on common columns, combining
rows with equal values in those columns.
- **Example:** `Employees ⨝ Departments` combines employee data with
department data based on department IDs.
- **Union (∪)**: Combines rows from two tables, eliminating duplicates.
- **Example:** `Employees ∪ Contractors`
- **Cartesian Product (×)**: Returns all possible combinations of rows from two
tables.
- **Example:** `Employees × Departments` returns all possible combinations
of employees and departments.
46. **Consider the following schema and represent given statements in relational
algebra form:**
- **Schema:**
- `Branch(branch_name, branch_city)`
- `Account(branch_name, acc_no, balance)`
- `Depositor(Customer_name, acc_no)`
- **(i) Find out list of customers who have an account at the 'abc' branch.**
- **Relational Algebra:** `π (Customer_name) (σ (branch_name = 'abc')
(Account) ⨝ Depositor)`
- **(ii) Find out all customers who have an account in the 'Ahmedabad' city and
balance is greater than 10,000.**
- **Relational Algebra:** `π (Customer_name) (σ (balance > 10000) (Account)
⨝ (σ (branch_city = 'Ahmedabad') (Branch) ⨝ Account) ⨝ Depositor)`
- **(iii) Find out list of all branch names with their maximum balance.**
- **Relational Algebra:** `π (branch_name, balance) (Account ⨝ (π
(branch_name, max_balance) (Account ⨝ (π (branch_name, MAX(balance) as
max_balance) (Account))))`
- **Difference (−)**: Retrieves tuples from the first relation that are not in the
second.
- **Cartesian Product (×)**: Returns all possible combinations of tuples from
two relations.
Unit 5.
To find the closure of a set of functional dependencies, you need to compute all the
attributes that can be functionally determined by a given attribute set.
Armstrong’s axioms are a set of inference rules used to derive all functional
dependencies implied by a given set of functional dependencies. They help in
reasoning about FDs and ensuring completeness and consistency in relational
database design. The axioms are:
These rules are used to derive additional functional dependencies and to check
whether a given functional dependency is implied by a set of functional
dependencies.
**52. Let \( R = (A, B, C, D, E, F) \) be a relation scheme with the following
dependencies:
\( C \rightarrow F \),
\( E \rightarrow A \),
\( EC \rightarrow D \),
\( A \rightarrow B \). Find the closure of FD.**