Database Management System
Database Management System
**Example:**
Consider a table named `Students`, with columns `StudentID`, `Name`, `Age`,
and `Major`. The `StudentID` could serve as the primary key because it uniquely
identifies each student.
Students Table:
+-----------+---------+-----+---------+
| StudentID | Name | Age | Major |
+-----------+---------+-----+---------+
|1 | Alice | 20 | Biology |
|2 | Bob | 22 | Chemistry |
|3 | Charlie | 21 | Physics |
+-----------+---------+-----+---------+
```
Foreign Key
A **Foreign Key** is a column (or a set of columns) in one table that refers to
the primary key of another table. The purpose of the foreign key is to enforce
referential integrity between the data in the two tables. This means it creates a
link between the tables, ensuring that the relationship between them remains
consistent. A foreign key in one table points to a primary key in another table,
establishing a relationship between the two tables.
**Example:**
Imagine we have another table called `Enrollments`, which records the courses
students have enrolled in. It includes columns like `EnrollmentID`, `StudentID`
(which refers back to the `StudentID` in the `Students` table), and `Course`.
Enrollments Table:
+--------------+-----------+----------+
| EnrollmentID | StudentID | Course |
+--------------+-----------+----------+
|1 |1 | Biology 101 |
|2 |2 | Chemistry 101 |
|3 |1 | Physics 101 |
+--------------+-----------+----------+
```
In the `Enrollments` table, `StudentID` serves as a foreign key because it
references the `StudentID` primary key in the `Students` table. This establishes a
relationship between each enrollment record and the corresponding student,
ensuring that enrollments can only be recorded for students that actually exist in
the `Students` table.
### Summary
- A **Primary Key** uniquely identifies each record within a table and cannot
be null.
- A **Foreign Key** creates a relationship between two tables by referencing the
primary key of another table, ensuring referential integrity.
Q.2) Centralised Database and Distributed Database.
Ans:
Centralized Database
Imagine your school's library where all books, journals, and resources are stored
in one main location. If anyone from anywhere in the school wants to borrow a
book or access a resource, they have to go to this single library. A **centralized
database** works much like this library. All the data is stored in one central
location (like a single server or data center), and users from different locations
access this data over a network.
**Advantages:**
- **Simplicity**: Easier to maintain and manage because everything is in one
place.
- **Consistency**: Since there's only one version of the data, it's easier to ensure
data accuracy and consistency.
- **Security**: Centralizing data can simplify the enforcement of security
policies and procedures.
Distributed Database
Now, think about a franchise restaurant chain, like McDonald's. Each restaurant
has its own storage of ingredients, but they all follow the same standards and
recipes. A **distributed database** is similar; it spreads the data across different
locations (servers situated in different geographical locations), yet operates as a
single database system. Even though the data is distributed, users can access and
manage it as if it were all in one place.
**Advantages:**
- **Reliability**: If one server fails, the system can continue to operate using the
data stored in other locations.
- **Local Control**: Different branches or departments can control their own
data, which can improve efficiency and response times.
- **Scalability**: It's easier to add more servers or locations to handle increased
load, improving performance and capacity.
Q.3) Roll-Back transaction.
Ans:-
In database management, a **rollback** operation is used to revert the database
to its previous state before a set of transactions were executed. This is particularly
useful in maintaining data integrity in cases where a transaction or a group of
transactions encounters an error or does not complete as expected. The rollback
operation undoes all changes made during the transaction.
Scenario
Imagine you are managing an online bookstore database. You have a table named
`Books` with columns `BookID`, `Title`, and `Stock`.
Let’s say you want to update the stock for a book and then perform another
operation, like updating the price. If the second operation fails for some reason,
you might want to undo the stock update as well to keep your data consistent.
### 3. **Security**
- **Protector of Data**: DBAs are responsible for securing the database against
unauthorized access, much like a bank vault manager ensures that the vault is
secure. This involves setting up user accounts, defining what data users can
access, and protecting against external threats like hackers.
Imagine you have a giant room full of filing cabinets where you keep all your
documents and files. This room is like your computer's **File System**. It's a
way of organizing and storing your files on storage devices like hard drives or
SSDs. In this room, each drawer represents a folder, and within these drawers,
you have files. You can easily go to a specific drawer to find a document, but if
you have thousands of documents, finding the one you need might take a while,
especially if they're not well organized.
Now, imagine instead of this room, you have a librarian in a library. This librarian
has a detailed catalog that tells exactly where each book is, who borrowed it last,
and when it's due back. This library is like a **Database System**. It's not just
about storing data (or books, in this analogy); it's also about managing the data—
keeping track of where it is, ensuring it's consistent, and controlling who can
access it. In a database system, data is stored in tables, which are like the catalog
entries in our library. These tables make it very efficient to search for, update, or
analyze data.
### File System
- **Simple Organization**: Like a room full of filing cabinets, it organizes data
into files and folders.
- **Direct Access**: You can directly access and open files without needing a
special method or query language.
- **No Complex Relationships**: It's great for storing individual files but doesn't
handle complex relationships between data (like linking a customer to their
orders) very well.
- **Manual Search**: Finding specific data might require manually searching
through files or folders, which can be time-consuming.
Imagine you're the captain of a ship navigating through a vast ocean. You have
charts, a compass, weather data, and your own experience to help you make
decisions about the best route, when to sail, and when to avoid bad weather. A
**Decision Support System (DSS)** is like having an expert navigator and a
weather forecasting system on board. It gathers all sorts of information—maps,
weather reports, data on currents and tides—and then, using technology, helps
you analyze this data to make informed decisions about your voyage. In a
business context, a DSS helps managers make decisions by providing
information, data analysis, and possible outcomes for different decisions. It's like
a toolkit that helps you see the bigger picture and weigh your options more clearly
before making a decision.
Data Redundancy
Now, imagine you have several notebooks where you jot down notes about your
journey, the crew's schedule, inventory, etc. If you write the same information in
multiple notebooks, you're doing extra work, and there's a chance the information
might not match up exactly if you update one notebook and forget to update the
others. This situation is similar to **data redundancy** in the world of data
management. It means the same piece of data is stored in more than one place.
While sometimes it's done on purpose for backup or quick access, it often leads
to extra storage being used, inconsistencies in data if not all instances are updated
together, and more effort required to manage the data.
Imagine your kitchen, where you have different ingredients stored in various
containers, each labeled and organized on shelves. Whenever you want to cook a
meal, you go to these containers, take what you need in the exact amount, and use
them to prepare your dish. A **database** is like this kitchen for digital
information. It stores data in a structured format, using tables (like shelves) and
records (like containers) that are easily accessible, searchable, and updatable. Just
as you can quickly find and use kitchen ingredients to make a meal, you can
quickly access and use data in a database to perform tasks, answer questions, or
support applications in real-time operations.
Imagine you're on a treasure hunt, but instead of looking for gold in a vast ocean,
you're searching for valuable insights within a massive sea of data. Data mining
is the process of discovering patterns, correlations, and anomalies within large
datasets. It's like having a map and a set of tools that help you identify where the
treasure (valuable information) is buried.
Once you've found the treasure, you need to figure out what to do with it.
Artificial Intelligence is like having an expert on board who can analyze the
treasure (data insights) you've found and make intelligent decisions. AI uses
algorithms and models to mimic human intelligence, making decisions,
predicting outcomes, and learning from data.
1. **Feeding the AI with Data**: AI systems need data to learn and make
decisions. Data mining extracts and prepares this data, serving as the food that
nourishes AI algorithms. Without data mining, AI systems wouldn't have the
quality data they need to operate effectively.
### 1. **Objects**
### 2. **Classes**
Classes are like the blueprint or design for a box. They describe what each box
should contain and how it should behave. If "DVD Player" is a class, then each
DVD player you produce according to this blueprint is an object of that class. The
class ensures that all DVD player objects have the same characteristics and
behaviors.
### 3. **Encapsulation**
Encapsulation is about keeping the contents of each box and the instructions on
how to use them together, and not letting anyone mess with them directly unless
they use the provided instructions. This means that the data (attributes) and the
operations (methods) are bundled together, and the internal workings are hidden
from the outside, ensuring a controlled interaction with the object’s data.
### 4. **Inheritance**
Inheritance is a bit like creating a new box design based on an existing one but
with some additions or changes. For instance, if you have a box design for a
"Basic DVD Player" and you want to make a "Blu-ray DVD Player," you don't
start from scratch. Instead, you take the "Basic DVD Player" design and add
features to play Blu-ray discs. The "Blu-ray DVD Player" inherits all the
characteristics of the "Basic DVD Player" and adds some more.
### 5. **Polymorphism**
Polymorphism is the ability to treat different objects—each with their own set of
instructions—through a common interface. Imagine you have different boxes,
one for a DVD player and another for a Blu-ray player. Polymorphism allows you
to use them through a common set of commands like "Play," "Stop," and "Eject,"
even though the specific way these commands are executed might differ for each
player.
This is like deciding exactly what to do with an object at the last possible moment.
For example, if you have a remote control with a "Play" button, dynamic binding
is what allows the system to decide whether to use the DVD player or the Blu-
ray player's "Play" function when you press the button, depending on which
player you're currently using.
Message passing is the process of sending instructions to the boxes. If you want
a DVD player to play, you send a "Play" message to it. This is how objects interact
with each other, with one object sending a request to another object to invoke a
method.
Q.10) How RDBMS Changes Life.
Ans:-
Before the advent of Relational Database Management Systems (RDBMS),
imagine organizing a vast collection of different types of information—like your
personal contacts, music collection, and book library—using physical ledgers or
index cards. Each type of information might be stored in a different format,
requiring you to remember where everything is and how it's organized. Finding a
specific piece of information, especially if it's related to other information, could
be like going on a treasure hunt without a map.
Enter RDBMS, which revolutionized how we store, retrieve, and manage data.
Think of RDBMS as a super-organized digital librarian who not only knows
where everything is but can also show you connections between different pieces
of information quickly and efficiently.
2. **Data Integrity and Accuracy**: RDBMS enforces rules to ensure that the
data entered is accurate and consistent, reducing errors. For example, it can
prevent you from accidentally entering a letter where a phone number should be
or adding the same contact twice.
3. **Efficient Data Retrieval**: Imagine asking the digital librarian for all your
friends who live in New York and like jazz. With RDBMS, retrieving this
information is as simple as running a quick search query, which can comb through
thousands of records in seconds to find exactly what you need.
### Security
Imagine your home where you keep valuable belongings. Security, in this context,
refers to the measures you take to protect your home from intruders, such as locks
on the doors, alarm systems, or even surveillance cameras. In the digital world,
security serves a similar purpose for protecting data.
### Integrity
While security focuses on protecting data from external threats, integrity is about
maintaining the accuracy and consistency of data over its entire lifecycle. It
ensures that the data is reliable and correct, regardless of how many times it is
accessed or updated.
#### Key Aspects of Data Integrity:
1. **Data Accuracy**: Ensuring the data correctly reflects the real-world values
or events it is supposed to represent. It's like making sure the books in your library
have the right information.
2. **Consistency**: Data remains consistent across the database, even after
various operations like updates or deletions. For example, if you update your
address in one place, it should automatically update everywhere.
3. **Constraint Enforcement**: Applying rules to the data to ensure it adheres to
certain standards or formats, like making sure every phone number includes a
country code.
4. **Reliability**: Making sure the data can be relied upon for making decisions
or performing operations, akin to trusting the accuracy of a recipe in a cookbook.
5. **Non-repudiation**: Ensuring that actions performed on or with the data
cannot be denied later, similar to signing a contract that binds you to an
agreement.
a. List the names, street addresses and cities of residence of all employees
who work for "Zeal Technologies Pvt. Ltd." and earn more than Rs. 35000.
b. List the names of all employees in this database who have joined the
company "Zeal Technologies Pvt. Ltd." after 31st of March 2022
c. List the names of all the employees whose manager's name's 3rd character
is s
d. List the names of all the employees who have taken loan of more than
Rs.15000 after 31st March 2022.
Ans:- Q1. 1> List the names, street addresses and cities of residence of all
employees who work for “Zeal Technologies Pvt. Ltd.” and earn more than Rs.
35000.Ans:
Q1. 2> List the names of all employees in this database who have joined the
company “Zeal Technologies Pvt. Ltd.” after 31st of March 2022
Ans:
SELECT empname
FROM employee
WHERE companyname = 'Zeal Technologies Pvt. Ltd.' AND dateofJoining >
'2022-03-31';
Q1. 3> List the names of all the employees whose manager's name's 3rd character
is “s”
Ans:
SELECT empname
FROM employee
WHERE SUBSTRING(managername, 3, 1) = 's';
Q1. 4> List the names of all the employees who have taken loan of more than
Rs.15000 after 31st March 2022.
Ans:
SELECT e.empname
FROM employee e
JOIN emploan el ON e.empno = el.empno
WHERE el.amount > 15000 AND el.dateofloan > '2022-03-31';