0% found this document useful (0 votes)
31 views15 pages

Key Concepts in DBMS: SQL & Normalization

The document covers various concepts related to Database Management Systems (DBMS), including foreign keys, aggregate functions, SQL commands like ORDER BY and GROUP BY, and normalization forms. It explains the purpose and syntax of views, transactions, and different types of locks, as well as concepts like atomicity, consistency, and isolation. Additionally, it discusses transaction management schemes and anomalies that can arise during concurrent execution.

Uploaded by

PAVANKUMAR KOTNI
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views15 pages

Key Concepts in DBMS: SQL & Normalization

The document covers various concepts related to Database Management Systems (DBMS), including foreign keys, aggregate functions, SQL commands like ORDER BY and GROUP BY, and normalization forms. It explains the purpose and syntax of views, transactions, and different types of locks, as well as concepts like atomicity, consistency, and isolation. Additionally, it discusses transaction management schemes and anomalies that can arise during concurrent execution.

Uploaded by

PAVANKUMAR KOTNI
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

DBMS MID-2 2 MARKS

UNIT-3 PART-B
1. What is a “Foreign Key ” explain with an appropriate
example
1A) A Foreign Key is a column or a group of columns in a
table that links to the primary key of another table. It is
used to maintain referential integrity between the two
tables, ensuring that the value in the foreign key column
matches a value in the referenced table’s primary key
column.
Example:
CREATE TABLE Orders (
OrderID INT PRIMARY KEY,
CustomerID INT,
OrderDate DATE,
FOREIGN KEY (CustomerID) REFERENCES
Customers(CustomerID)
);
In this example, CustomerID in the Orders table is a
foreign key that references the CustomerID in the
Customers table.

2. List all Aggregate Functions


2A) Aggregate functions perform calculations on a set of
values and return a single result. The common aggregate
functions in SQL are:
1. COUNT(): Returns the number of rows in a set.
2. SUM(): Returns the sum of a set of values.
3. AVG(): Returns the average of a set of values.
4. MIN(): Returns the smallest value in a set.
5. MAX(): Returns the largest value in a set.

3. State the purpose of ‘ORDER BY’ keyword and write the


detailed syntax.
3A) The ORDER BY keyword is used to sort the result set
of a query by one or more columns. It can sort data in
ascending (default) or descending order.
Syntax:
SELECT column_name(s)
FROM table_name
ORDER BY column_name [ASC | DESC];
Example:
SELECT Name, Age
FROM Employees
ORDER BY Age DESC;
This query sorts the Employees table by Age in
descending order.

4. State the purpose of ‘GROUP BY’ keyword and write it’s


syntax.
4A) The GROUP BY keyword is used to group rows that
have the same values into summary rows. It is often used
with aggregate functions like COUNT(), SUM(), AVG(), etc.,
to perform operations on each group.
Syntax:
SELECT column_name(s),
aggregate_function(column_name)
FROM table_name
GROUP BY column_name(s);
Example
SELECT DeptID, COUNT(*)
FROM Employees
GROUP BY DeptID;
This query groups the employees by DeptID and returns
the number of employees in each department.

5. List all Relational Set operators


5A) The relational set operators in SQL are:
1. UNION: Combines the result sets of two queries,
eliminating duplicates.
2. INTERSECT: Returns only the common rows between
two queries.
3. EXCEPT (or MINUS in some DBMS): Returns rows from
the first query that are not present in the second query.
4. UNION ALL: Combines the result sets of two queries,
including duplicates.

6)What is a View in SQL? write it’s syntax.


6A) A View is a virtual table based on the result of a
SELECT query. It does not store data itself but displays
data stored in one or more tables.
Syntax:
CREATE VIEW view_name AS
SELECT column1, column2, ...
FROM table_name
WHERE condition;
Example:
CREATE VIEW EmployeeView AS
SELECT Name, Age
FROM Employees
WHERE Age > 30;
This creates a view EmployeeView that shows
employees older than 30 years.
7)What is an Updated View
7A) An Updated View is a view that is modifiable,
allowing you to perform INSERT, UPDATE, or DELETE
operations on the underlying tables through the view.
Not all views are updatable; it depends on the query
structure.
8. List the different types in Ordering
8A) There are two main types of ordering in SQL:
1. Ascending (ASC): Orders data from smallest to largest
(default).
2. Descending (DESC): Orders data from largest to
smallest.

9. Whatis Intersect operation on two data sets


9A) The INTERSECT operator returns only the rows that are
common between two data sets. It removes duplicates and
returns distinct rows.
Example:
SELECT Name FROM Employees
INTERSECT
SELECT Name FROM Managers;
This returns the names that are both in Employees and
Managers tables.
10. Write short note on EXCEPT condition
10A) The EXCEPT (or MINUS in some databases) operator
returns rows from the first query that are not present in the
second query. It eliminates duplicates.
Example:
SELECT Name FROM Employees
EXCEPT
SELECT Name FROM Managers;
This returns the names of employees who are not
managers.

11. What is Union operation on two data sets


11A) The UNION operator combines the results of two
queries into a single result set and eliminates duplicate
rows.
Example:
SELECT Name FROM Employees
UNION
SELECT Name FROM Managers;
This query returns all unique names from both the
Employees and Managers tables.

12. Write a short note on Nested Query


12A) A Nested Query (or subquery) is a query inside another
query. It is used to perform operations that require
intermediate results, allowing one query to depend on
another.
Example
SELECT Name
FROM Employees
WHERE DeptID = (SELECT DeptID FROM Departments
WHERE DeptName = 'IT');
This query selects employees who belong to the IT
department by using a nested query to find the DeptID of
the IT department.

UNIT-4 2 MARKS
1. Expand BCNF
1A) BCNF stands for Boyce-Codd Normal Form — a type of
database normalization used to reduce redundancy and
avoid anomalies.

2. Expand MVD
2A) MVD stands for Multivalued Dependency — it occurs
when one attribute in a table uniquely determines
another attribute, independent of all others.
3. What is a Functional Dependency
3A) A Functional Dependency is a relationship where one
attribute uniquely determines another attribute.
Example: If A → B, then knowing A means you can
determine B.
4. What is a Closure explain with an Example
4A) The closure of a set of attributes is the set of all
attributes that can be functionally determined from it.
Example:
If A → B and B → C, then Closure(A) = {A, B, C}.

5. List the advantages of Normalization


5A)
 Reduces data redundancy.
 Avoids data anomalies.
 Improves data integrity.
 Makes database design efficient.

6. What is the other name of BCNF


6A) BCNF is sometimes referred to as a stronger version of
the Third Normal Form (3NF).
7. State the Rule of First Normal Form
7A) A table is in First Normal Form (1NF) if all its columns
contain atomic (indivisible) values, and each record is
unique.
8. What is Strict Normal Form
8A) Strict Normal Form usually refers to the Boyce-Codd
Normal Form (BCNF), where even slight redundancy is
removed.
9. What is the Rule for 2 nd Normal Form
9A) A table is in Second Normal Form (2NF) if:
 It is in 1NF.
 No partial dependency exists (non-prime attributes
must fully depend on the primary key).

10. What is the Rule for 3rd Normal Form


10A) A table is in Third Normal Form (3NF) if:
 It is in 2NF.
 No transitive dependency exists (non-prime attributes
must depend only on the primary key).

11. What is Transitive Dependency


11A) A Transitive Dependency occurs when one non-
prime attribute depends on another non-prime attribute
rather than directly on the primary key.
Example:
If A → B and B → C, then C is transitively dependent on A.

[Link] is a Prime Attribute


12A) A Prime Attribute is an attribute that is part of any
candidate key of a relation.
13) What is a Non-Prime Attribute
13A) A Non-Prime Attribute is an attribute that is not part of
any candidate key.

14). What is De-Normalization


14A) De-Normalization is the process of intentionally
introducing redundancy into a database for performance
optimization purposes.
15),What is a Super Key
15A) A Super Key is any set of attributes that uniquely
identifies a record in a table.
Example:
{RollNo, Name} is a super key if RollNo uniquely identifies a
student.

16)What is a Candidate Key


16A) A Candidate Key is the minimal set of attributes that
can uniquely identify a tuple in a table.
It is a minimal super key.
17)What is a Foreign Key
17A) A Foreign Key is a field (or collection of fields) in one
table that refers to the primary key in another table,
maintaining referential integrity.

18)What is a Surrogate Key


18A) A Surrogate Key is an artificial key assigned to each
record, usually a number, that uniquely identifies a record
without using real-world data.
Example:
An auto-incremented ID field.

UNIT-5 2 MARKS
Unit-V-Short Questions
1. Define Transaction
1A) A Transaction is a logical unit of work that must
be either completely completed or aborted. It
consists of a sequence of operations performed as a
single logical unit.

2. What is Atomicity
2A) Atomicity ensures that either all operations of a
transaction are completed or none of them are.
There is no partial execution.
3. What is Consistency
3A) Consistency ensures that a transaction brings the
database from one valid state to another valid state,
maintaining database rules like constraints.
4. What is Isolation
4A) Isolation means that concurrent transactions are
executed independently, without interfering with
each other’s operations and results.

5. What is Durability
5A) Durability ensures that once a transaction
commits, its changes are permanently stored in the
database, even if a system failure occurs.
6. Discuss Validation Phase
6A) The Validation Phase in optimistic concurrency
control verifies if the transaction can commit
without violating consistency, by checking if it
conflicts with other transactions.

7. List all Lock Based Protocols


 7A) Two-Phase Locking (2PL)
 Strict Two-Phase Locking
 Conservative Two-Phase Locking
 Rigorous Two-Phase Locking

8. List the types of failures


 8A) Transaction Failures
 System Crash
 Disk Failure
 Communication Errors

9. Distinguish Shared Lock and Exclusive Lock


 9A) Shared Lock (S-lock): Allows multiple transactions
to read but not modify the item.
 Exclusive Lock (X-lock): Allows only one transaction to
read and modify the item.

10. List various anomalies that arise due to


parallel execution of transactions
 10A) Lost Update
 Temporary Update (Dirty Read)
 Incorrect Summary
 Unrepeatable Read
11. Write about recovery facilities in transaction
management.
11A) Recovery facilities include:
 Log-Based Recovery
 Checkpoints
 Shadow Paging
They help restore the database to a consistent state
after a failure.

12. Write about wait die scheme in transaction


management.
12A) In Wait-Die Scheme, if an older transaction
requests a lock held by a younger one, it waits;
otherwise, it is aborted ("dies") and restarted later.
13. What is a Conflict
13A) A Conflict occurs when two transactions try to
access the same data item, and at least one of them
is performing a write operation.
14. What is Dirty Read in concurrent execution
14A) A Dirty Read happens when a transaction reads
data written by another uncommitted transaction,
which may later be rolled back.

15. Write about wound wait scheme in


transaction management.
15A) In Wound-Wait Scheme, if an older transaction
requests a lock held by a younger one, it forces the
younger one to abort ("wound"); otherwise, the
older transaction waits.

Common questions

Powered by AI

A Nested Query, or subquery, is a query within another SQL query, allowing for more complex and flexible data manipulations. It is used to perform operations that require intermediate data results, letting one query depend on the results of another. For instance, to select employees who belong to the 'IT' department, you might query: SELECT Name FROM Employees WHERE DeptID = (SELECT DeptID FROM Departments WHERE DeptName = 'IT'). Here, the inner query finds the DeptID matching 'IT', while the outer query uses this result to fetch the relevant employee names. This technique streamlines complex data retrieval processes .

The 'UNION' operation in SQL combines the results of two queries and eliminates duplicate rows in the process, useful when consolidating data from different tables with similar structures. An example is combining employee names from multiple departments. On the other hand, the 'INTERSECT' operation returns only the common rows from two datasets, eliminating duplicates. This is useful for identifying records present in both sets, such as common clients in customer databases. Each serves distinct purposes: 'UNION' for broad data aggregation, while 'INTERSECT' is optimal for finding overlaps between datasets .

Views in SQL act as virtual tables that present the results of a query. They offer advantages like simplifying complex queries, providing a layer of security by restricting access to specific data, and centralizing complex logic. Views can also help in maintaining a consistent interface regardless of changes in base tables. However, they can pose drawbacks, such as performance overhead in query execution and limitations on update operations if the underlying query does not meet specific criteria for updatability. Overall, while views are powerful tools for managing database presentation and access, they must be used judiciously to balance functionality and system performance .

The ACID properties ensure reliable processing of transactions in database systems. Atomicity guarantees that all operations in a transaction are completed or none are—preventing partial updates. Consistency maintains database rules, ensuring transactions bring the database from one valid state to another. Isolation prevents transactions from affecting each other uncontrollably, preserving data integrity in concurrent operations. Durability ensures that committed transaction changes persist even in case of system failures. Together, these properties maintain database reliability, preventing errors that could occur in complex transaction scenarios in shared database environments .

Aggregate functions in SQL are used to perform calculations on a set of values to return a single result, which is particularly useful for summarizing data. Key aggregate functions include COUNT(), which counts rows; SUM(), which totals the values of a column; AVG(), which calculates the average of a numeric column; MIN() and MAX(), which return the smallest and largest values, respectively. These functions are commonly used in data analytics for generating reports where summarization of data, like total sales or average temperature, is needed .

Normalization in database design aims to reduce data redundancy and improve data integrity by structuring tables to satisfy normal forms, which eliminates anomalies during data operations like updates. The process simplifies the understanding of relationships and ensures consistent data entry. However, overly normalized tables can lead to complex queries and increased join operations, affecting performance. De-normalization, conversely, introduces some redundancy intentionally to optimize read performance by reducing the need for complex joins, though at the risk of increased redundancy and potential anomalies. The decision between normalization and de-normalization hinges on balancing consistency with performance needs .

Lock-based protocols, such as Two-Phase Locking (2PL), Strict 2PL, Conservative 2PL, and Rigorous 2PL, are crucial in concurrency control by regulating access to database items. In 2PL, a transaction can acquire locks, ensuring no new locks are acquired once a lock is released. Strict 2PL locks a data item until the transaction is complete, providing serializability and simplifying recovery. Conservative 2PL seeks to prevent deadlocks by acquiring all locks before transactions start. Rigorous 2PL ensures thorough control by keeping all locks until after the transaction commits, further enhancing consistency and durability. These protocols mitigate conflicts and preserve transaction integrity .

Functional dependency occurs when one attribute uniquely determines another attribute, forming the basis for defining relationships among columns in a table. For example, if A → B, knowing A means you can determine B. Transitive dependency occurs when a non-prime attribute is indirectly dependent on the primary key via another non-prime attribute. An example is A → B and B → C, making C transitively dependent on A. Understanding these dependencies is crucial for database normalization, which aims to minimize redundancy and anomalies in data manipulation by ensuring that each table in the database structure adheres to normal form criteria, such as third normal form (3NF).

The 'ORDER BY' clause in SQL is used to sort the result set of a query by one or more columns in ascending or descending order, enhancing data readability and organization. For example, sorting a list of employees by descending age helps quickly identify the oldest employees. Conversely, the 'GROUP BY' clause is employed to aggregate data across rows that share common values in specified columns, often paired with aggregate functions. This helps in summarizing extensive datasets into meaningful groups, like counting employees per department. Both commands fundamentally shape data retrieval processes to satisfy specific analytic and reporting needs .

A foreign key is a column or group of columns in a database table that provides a link between the data in two tables by referencing the primary key of another table. This key is crucial for enforcing referential integrity, ensuring that the data is consistent and accurately linked between tables. For example, in a database with tables Orders and Customers, the CustomerID in Orders can be set as a foreign key that references the primary key, CustomerID, in the Customers table. This relationship ensures that every order is associated with a valid customer entry, preventing orphan records and maintaining database integrity .

You might also like