Dbms pt1
Dbms pt1
Question Bank:
1-Give the Drawbacks of File Processing System?
1. Ans-Data Redundancy: In FPS, the same data may be stored in multiple files, leading to
duplication and wastage of storage space12.
2. Data Inconsistency: Due to data redundancy, different files may contain different
values for the same data, causing inconsistencies12.
3. Limited Data Sharing: Sharing data between different applications or users is difficult
because files are often isolated and not integrated23.
4. Poor Data Integrity: Ensuring data integrity is challenging as there are no centralized
constraints or rules to enforce data accuracy and consistency1.
5. Security Issues: FPS lacks robust security measures, making it difficult to control
access to sensitive data3.
7. Data Isolation: Data is scattered in various files, making it hard to retrieve and
combine data from different sources12.
These drawbacks highlight why many organizations have transitioned to using DBMS, which
offers more efficient, secure, and reliable data management.
1. Ans-DBMS (Database Management System): A software system that enables the creation,
management, and manipulation of databases. It provides tools for data storage, retrieval, and
management, ensuring data integrity, security, and consistency.
2. Database: An organized collection of structured data, typically stored electronically in
a computer system. A database allows for efficient data retrieval, insertion, and
management.
3. Query: A request for data or information from a database. Queries are written in a
specific language, such as SQL, to retrieve, update, or manipulate data.
4. Tables: Structures within a database that organize data into rows and columns. Each
table represents a specific entity, with columns representing attributes and rows
representing records.
5. Records: Individual entries in a table, also known as rows. Each record contains data
for a specific instance of the entity represented by the table.
6. Key: An attribute or a set of attributes that uniquely identifies a record in a table. Keys
are used to establish and enforce relationships between tables.
7. Candidate Key: An attribute or a set of attributes that can uniquely identify a record
in a table. A table can have multiple candidate keys, but only one can be chosen as
the primary key.
8. Foreign Key: An attribute or a set of attributes in one table that references the
primary key of another table. Foreign keys are used to establish relationships
between tables and ensure referential integrity.
9. Primary Key: A specific candidate key chosen to uniquely identify records in a table.
The primary key must contain unique values and cannot contain NULL values.
10. DDL (Data Definition Language): A subset of SQL used to define and manage
database structures, such as creating, altering, and deleting tables and other
database objects. Examples include CREATE, ALTER, and DROP.
11. DML (Data Manipulation Language): A subset of SQL used to manipulate data within
database tables. It includes commands for inserting, updating, deleting, and
retrieving data. Examples include INSERT, UPDATE, DELETE, and SELECT.
2. Data Sharing: DBMS allows multiple users and applications to access and
share data concurrently, while FPS makes data sharing complex and less
efficient12.
3. Data Integrity: DBMS enforces data integrity through constraints and
rules, ensuring data accuracy and consistency. FPS lacks automated
integrity checks, leading to potential errors2.
4. Data Security: DBMS provides robust security features, including user
authentication, authorization, and encryption, protecting sensitive data.
FPS generally lacks these advanced security measures2.
9. Scalability: DBMS can handle large datasets and scale efficiently as data
grows, while FPS may struggle with performance and management as
data volume increases2.
4. TRUNCATE: This command removes all records from a table but retains
the structure of the table for future use. It's faster than deleting rows
one by one but does not trigger any DELETE triggers.
o Example:
sql
Copy code
TRUNCATE TABLE Employees;
1. SELECT: This command retrieves data from one or more tables. It can
include complex queries with filtering, sorting, and joining of tables.
INSERT: This command adds new rows to a table.
UPDATE: This command modifies existing rows in a table based on
specified criteria.
DELETE: This command removes rows from a table based on specified
criteria.
1. BOOLEAN:
o Description: Stores boolean values (true or false).
o Example: BOOLEAN (or BOOL, depending on the
database)
Miscellaneous Data Types
1. UUID:
o Description: Stores universally unique identifiers.
o Example: UUID (format: 36-character string)
2. ENUM:
o Description: Stores a value from a predefined list of
values. o Example: ENUM('red', 'green', 'blue')
3. SET:
o Description: Stores a set of predefined values.
o Example: SET('a', 'b', 'c') (can store any combination
of the defined values)
19- Describe aggregate functions with example
Ans- 1. COUNT
Description: Counts the number of rows in a set or
the number of non-NULL values in a column.
Example:
sql
SELECT COUNT(*) AS TotalEmployees
FROM Employees;
This query counts the total number of rows in the
Employees table.
Example with a specific column:
sql
SELECT COUNT(Email) AS EmailCount
FROM Employees;
This query counts the number of non-NULL values
in the Email column of the Employees table.
2. SUM
Description: Adds up all the values in a numeric
column. Example:
sql
SELECT SUM(Salary) AS TotalSalary
FROM Employees;
This query calculates the total sum of all salaries in
the Employees table.
3. AVG
Description: Calculates the average value of a
numeric column.
Example:
sql
SELECT AVG(Salary) AS AverageSalary
FROM Employees;
This query computes the average salary of all
employees in the Employees table.
4. MIN
Description: Returns the smallest value in a
column. Example:
sql
SELECT MIN(Salary) AS LowestSalary
FROM Employees;
This query finds the lowest salary in the Employees
table.
5. MAX
Description: Returns the largest value in a column.
Example:
sql
SELECT MAX(Salary) AS HighestSalary
FROM Employees;
This query finds the highest salary in the Employees
table.
6. GROUP_CONCAT (MySQL) /
STRING_AGG (PostgreSQL)
Description: Concatenates values from multiple
rows into a single string.
Example in MySQL:
sql
SELECT GROUP_CONCAT(FirstName) AS
AllFirstNames
FROM Employees;
This query concatenates all FirstName values into a
single comma-separated string.
Example in PostgreSQL:
sql
SELECT STRING_AGG(FirstName, ', ') AS
AllFirstNames
FROM Employees;
This query performs a similar operation in
PostgreSQL, concatenating FirstName values with a
comma and space separator.
7. VARIANCE / STDDEV
Description: Measures the statistical variance and
standard deviation of a numeric column.
Example for variance:
sql
SELECT VARIANCE(Salary) AS SalaryVariance
FROM Employees;
This query calculates the variance of salaries in the
Employees table.
Example for standard deviation:
sql
SELECT STDDEV(Salary) AS SalaryStdDev
FROM Employees;
This query calculates the standard deviation of
salaries.
Math, English,
1 Alice
History
1 Alice Math
1 Alice English
1 Alice History
StudentID Name Subject
2 Bob Science
2 Bob Math
Now:
Each column contains only atomic values.
There are no repeating groups.
Each row is unique.
This table is now in First Normal Form (1 NF).
2nf*
Second Normal Form (2NF) builds on the rules of First
Normal Form (1NF) and adds further requirements to
reduce redundancy and improve data integrity. To be in
2NF, a table must first be in 1NF, and then it must satisfy
the following conditions:
Key Rules of 2NF:
1. Meet the requirements of 1NF: The table must already be in
First Normal Form.
2. No Partial Dependency: Every non-key column must depend on
the entire primary key, not just a part of it. This rule applies
particularly when the primary key is composite (i.e., made up of
more than one column).
Example of a Table in 1NF but Not in 2NF:
Let's consider the table from the previous example,
assuming that a composite primary key consists of
StudentID and Subject.
Studen Na Subj Teac
tID me ect her
Mr.
Alic Mat
1 Smit
e h
h
Ms.
Alic Engli
1 John
e sh
son
Mr.
Alic Hist
1 Brow
e ory
n
Mr.
Bo Scie
2 Whit
b nce
e
Mr.
Bo Mat
2 Smit
b h
h
In this example:
StudentID and Subject together form the composite primary
key.
The Name column depends only on StudentID and not on the
entire primary key (i.e., it doesn't depend on Subject), which
creates a partial dependency.
The Teacher column depends only on Subject and not on the
entire composite primary key.
Converting to 2NF:
To convert this table to 2NF, we need to eliminate partial
dependencies by separating the table into two or more
tables.
Table 1: Student Information (StudentID as Primary Key)
StudentID Name
1 Alice
2 Bob
Table 2: Subject Information (Subject as Primary Key)
Subject Teacher
1 Math
1 English
1 History
2 Science
2 Math
Now:
The Name column in the first table depends only on StudentID.
The Teacher column in the second table depends only on
Subject.
The third table represents the relationship between students
and their subjects.
This structure eliminates partial dependencies and brings
the data into Second Normal Form (2NF).
3nf*
Ans-Third Normal Form (3NF) builds on the rules of
Second Normal Form (2NF) and adds an additional
requirement to eliminate transitive dependencies. To be
in 3NF, a table must first be in 2NF, and then it must
satisfy the following condition:
Key Rule of 3NF:
1. Meet the requirements of 2NF: The table must already be in
Second Normal Form.
2. No Transitive Dependency: A non-key column must not depend
on another non-key column. In other words, all non-key
columns must depend only on the primary key, not on other
non-key columns.
Example of a Table in 2NF but Not in 3NF:
Let's continue with the previous example, but add a new
column that violates 3NF. Assume the Subject table is
extended with a new column Department that indicates
the department responsible for the subject.
Table: Subject Information (Subject as Primary Key)
Subject Teacher Department
Math Science
English Arts
History Humanities
Science Science
Now:
The Teacher column depends only on Subject, and there are no
transitive dependencies in the Subject Information table.
The Department information has been moved to its own table,
which keeps the data normalized.
This structure eliminates transitive dependencies and
brings the data into Third Normal Form (3NF).
----------------------THE END------------------------------