Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

INTERNAL ASSIGNMENT

NAME DHANANJAY
ROLL NO 2214504860
SEMESTER
III

COURSE CODE & NAME


DCA2102 & Database Management
System

SESSION SEPTEMBER 2022


SET - I

Question .1.) What is a database? Differentiate between physical data independence and
logical data independence.

Ans: .:- Demystifying Databases: Dual-Level Independence

A database can be compared to a well arranged digital library. It keeps material in tables with
rows and columns rather like books on shelves, which makes it simple to access certain
pieces of information. Databases frequently have several levels of access and organizing,
much like libraries do. Data independence comes into play here.

The capacity to make changes at one database level without impacting other levels is known
as data independence. This enables you to be flexible and adaptive as your demands for data
change. Consider it like building a house: you shouldn't have to tear down the entire thing to
add a new room Data independence comes in two primary forms:

1. The independence of physical data:

Envision the interior design and foundation of the house. These serve as the database's
physical layer representation. The ability to change the underlying data structures, file
organisation, or storage techniques without affecting the upper layers is known as physical
data independence. Users' data access methods would remain the same if SSDs were to
replace HDDs as their primary storage option.

As an example:

Reindexing data for optimal efficiency; switching from hashing to B-trees for file structure;
upgrading storage media (HDD to SSD);

Benefits include: • Less reliance on particular hardware and software; • Better performance
and scalability; and • Easier database management and maintenance.

2. Independence of Logical Data:

Now see the spaces, pieces of furniture, and accents—the database's logical level. This level
establishes how users view and work with the schema-represented data. You may change the
logical organisation of the data without impacting external views or application programs
thanks to logical data independence. It's similar to rearrangement of furniture without actual
room modification.

As an illustration: Adding or deleting characteristics from a database; changing the


connections between tables; and developing fresh perspectives on already-existing data
Benefits include: • More flexible data modelling and schema evolution; • Simpler
application development and maintenance;

• Lessened user impact from data reorganisation

The database must have a layered design in order to achieve various kinds of independence:

• Internal Schema: Specifies the specifics of data storage as well as its physical location.

• Conceptual Schema: Regardless of implementation, it describes the general logical


structure of the data.

• External Schema: Depicts several user perspectives of the information according to their
requirements.

In order to preserve the logical definition (conceptual schema), the DBMS serves as a
mediator between both levels, converting user requests (external schema) into instructions for
accessing and altering data (internal schema).

Question .2.) Construct an E-R diagram for a hospital with a set of patients and a set of
medical doctors. Associate with each patient a log of the various tests and examinations
conducted.

Ans: E-R Diagram for Hospital Management System

Here's an E-R diagram for a hospital system with patients, doctors, and tests/examinations:

Entities:

1. Patient: Contains information about patients, including:

o Patient_ID: Unique identifier (primary key)

o Name: Full name

o Date_of_Birth: Birth date

o Address: Residential address

o Phone_Number: Contact number

o Insurance_Information: Insurance details

o Medical_History: Past medical history

2. Doctor: Contains information about doctors, including:


o Doctor_ID: Unique identifier (primary key)

o Name: Full name

o Specialisation: Medical specialty (e.g., Cardiology, Neurology)

o Department: Hospital department assigned (e.g., Emergency, Surgery)

○ Qualifications: Educational qualifications and certifications


○ Contact_Information: Contact details
2. Test/Examination: Contains details about tests and examinations conducted,
including:
○ Test_ID: Unique identifier (primary key)
○ Test_Name: Name of the test or examination (e.g., Blood Test, X-ray)
○ Description: Brief description of the test
○ Date_Performed: Date the test was conducted
○ Results: Test results and associated values

1. Relationships: Many-to-many between patient and doctor. Multiple physicians can treat
the same patient, and a doctor can treat more than one patient. Appointment is an associated
entity that represents this and consists of the following:

o Appointment_ID: The primary key, a unique identification

o Patient_ID: A foreign key that points to the patient

o Doctor_ID: Foreign key pointing to the physician

o Date_of_Appointment: The appointment date; o Diagnosis: The physician's assessment


given the appointment

The patient-test/examination connection is one-to-many. A patient may undergo more than


one examination, but only one patient is included in each test. In the Test/Examination object,
this is represented by the foreign key Patient_ID.

Relationships and Optional Entities:


• Nurse: Provides details on nurses, such as department and area of expertise.

• Medication: Provides details about the dose, timing, and prescription of drugs.

• Treatment: Information about treatment programs and carried out actions.

• Bill/Payment: Keeps track of patient invoices and money transfers.

Depending on the particular needs of the hospital management system, these more entities
may be introduced.

Notes: • Relationships can be shown with cardinality (e.g., one-to-many or many-to-many)


for further clarity.

• Primary and foreign keys are essential for connecting entities.

• Features may be further tailored in accordance with particular requirements (e.g., patient
allergies, emergency contact information). A hospital database may be modeled using the
fundamental structure provided by this E-R diagram. You may develop a strong system for
handling patient information, appointments, treatments, and billing by expanding and
improving it.

Question .3.) What is the goal of query optimization? Why is it important?

Ans: The Quest for Speed: Demystifying Query Optimization

Envision yourself in a huge library, trying to find a certain book. After being sent to the
general area by the librarian, you spend hours looking over several shelves. An unoptimized
database query will experience similar delays, inefficiencies, and frustrations. This is where
query optimization comes into play, saving you a ton of time and work by serving as your
virtual librarian and directing you to the precise shelf.

What then is query optimization trying to achieve? In short, the goal is to determine the
quickest and most effective method for retrieving data from a database. It's similar to creating
a well-written recipe for information extraction: with the correct components (techniques)
and directions (execution plan), you may get a tasty (timely) outcome.

1. Improved User Experience: No one likes to wait for an app to open or a website to load.
Quick data delivery via optimised queries makes for a more seamless and enjoyable user
experience. Quicker interactions keep consumers interested and interested in returning.

2. Enhanced Server Performance: A database that is inundated with wasteful queries finds
it difficult to keep up, much like an overworked kitchen. By lowering the server's burden,
optimization helps to avoid crashes and system slowdowns. Higher uptime and more
resources available for other activities are the results of this.

3. Lower Expenses: Ineffective searches waste time and money, which raises running
expenses. Hardware is used less when searches are optimised.

strain, resulting in reduced power use and longer device lifespan. Furthermore, quicker
processing increases the value of the current infrastructure by handling more inquiries in a
given amount of time.

4. Effective Data Management: Reduced disk access and data processing through optimised
queries spares storage systems needless deterioration. This lessens the chance of data loss and
lowers maintenance expenses in addition to extending their lifespan.

5. Scalability for Growth: Inefficient queries are more difficult to execute as databases get
bigger. Systems can grow and accommodate more users with ease because of optimization,
which keeps queries effective even with ever-increasing data quantities.

How does query optimization operate now? It's a multi-step procedure that includes:

• Examining the query: Knowing what information is needed and how the database makes
sense.

• Creating execution plans entails determining various query execution strategies and
projecting how well they will work.

• Selecting the best plan: Opting for the strategy that will execute the fastest while utilizing
the fewest resources and data processing.

• Carrying out the plan: obtaining the needed information quickly.

Although the particular methods differ based on the database system, typical optimization
tactics consist of:

• Indexing: Finding certain data in tables quickly and effectively.

• Join optimization: Selecting the most effective method for merging information from
several tables.

Materialisation: Preprocessing and archiving commonly used outcomes to facilitate quicker


retrieval.

• Denormalization: To cut down on joins, grouping related data into fewer tables.

In the end, query optimization is a continuous endeavor. Queries must be continuously


adjusted in response to changes in user demands and data evolution. You can make sure your
databases function like well-oiled machines, providing data quickly and effectively, keeping
users satisfied and systems running smoothly, by implementing optimization into your
database management approach.

SET - II

Question .4.) Explain any two important properties of transactions that a DBMS must
ensure to maintain data in the face of concurrent access and system failures.

Ans: Two crucial characteristics are necessary to preserve data integrity and consistency in
the busy world of databases, where several users and processes access and alter data
concurrently: atomicity and durability. These serve as the cornerstones of data protection,
protecting against system failures and concurrent access, which might potentially cause
chaos.

Atomicity: Picture a transfer of funds between two accounts at a bank. Merely taking money
out of one account is insufficient; the second account must also be credited in the same
amount, and both processes must be successful or unsuccessful. The fundamental idea behind
atomicity is this all-or-nothing strategy. It guarantees that a set of connected database
activities, or a transaction, is handled as a single, indivisible entity. The transaction's
operations either all finish successfully or none of them do. leaving the database consistent
prior to the transaction starting.

• Atomicity's advantages

o Prevents partial updates: This ensures that either both or none of the bank transfers are
completed, preventing a financial meltdown.

o Preserves data integrity: Guards against transactions that are incorrect or incomplete,
which may contaminate data.

o Simplifies error handling: Recovery is facilitated by the complete transaction rollback,


which streamlines error management.

• The DBMS's Atomicity Guarantee:

o Locking mechanisms: Locks guarantee exclusive access and avoid interference by


preventing other transactions from accessing data related to the ongoing transaction.

o Redo and rollback logs: These logs document modifications made during a transaction.
They enable the DBMS to successfully commit transactions on different data copies (redo) or
undo partial operations (rollback) in the event of a failure.

2. Durability: Let's say that a bank transfer takes place, but before the update is permanently
stored to storage, there is a power outage. If it isn't durable, the transfer just disappears!
Here's when durability becomes important. It ensures that, in the event of a system failure
such as a hardware breakdown or power loss, the modifications made by a transaction are
irreversibly preserved in the database.
The advantages of durability

o Guards against loss of data: ensures that important updates, such as the bank transfer,
continue uninterrupted even in the event of a crash.

o Maintains consistency of data: gives future transactions a solid base since they rely on
precise and comprehensive data.

o Promotes database confidence: Applications and users may depend on the database to
correctly report finished transactions.

• How Durability is Guaranteed by DBMS:

o Transaction logs: Before being applied to the database, changes performed during a
transaction are recorded in a transaction log. In the event of a malfunction, this log serves as
the fallback.

o Write-ahead logging (WAL): This makes sure that modifications are recorded in the
transaction log before the database is updated, ensuring full updates even in the event of a
crash.

o Backups and redundancies: Data is frequently backed up or saved across several systems
to provide copies in the event that the original storage fails.

Together, atomicity and durability ensure that data is secure even in the event of system
failures or concurrent access. Durability ensures that transactions are permanent, whereas
atomicity makes sure they are indivisible. These essential characteristics are implemented by
DBMSs, opening the door for dependable and consistent data management, even in the
busiest and most challenging environments.

Question .5.) What is relational completeness? If a query language is relationally


complete, can you write any desired query in that language?

Ans: Relational completeness is a sign of a query language's expressive capacity in the


context of databases. It means that every query on a relational database may be created using
just the language's built-in components, negating the need for extra programming or
procedural logic.

Below is a summary of its main ideas:

• Relational Model: In this model, information is arranged into tables, or relations, with each
row denoting a unique entity and each column denoting a characteristic of that object.

• Query Language: A language designed to work with databases, particularly for data
retrieval, manipulation, and analysis.
• Relational Completeness: If a query language can articulate any question that makes sense
inside the relational model, it is deemed relationally complete. In order for a language to be
considered relationally complete, it must facilitate four crucial operations:

1. Selection: Selecting particular rows (tuples) from a table in accordance with


predetermined standards.

2. Project: Pulling out particular columns (characteristics) from a table.

3. Union: Merging the rows of two tables having structurally compatible combinations.

4. Disparity: Discovering rows that are in one table but absent from another.

5. Cartesian Product: Merging all rows from one table with all rows from another to create
a new table.

6. Renaming: Giving tables or attributes new names.

Relational Completeness's Power:

• Expressiveness: Users are given the freedom to inquire about any possible topic regarding
the data in a relationally full language.

• Versatility: From basic data retrieval to intricate analysis and transformations, it can handle
a broad variety of queries.

• Portability: Across several database systems that support the same language, queries
written in relationally complete languages are frequently transferable.

But relational completeness does not imply that all possible questions can be expressed in
real-world scenarios. This is the reason why:

• Computational Constraints: Although a question may be theoretically formulated, it may


not be feasible to do it because of inadequate resources or lengthy processing times.

• Specific Language limits: Certain question formulations may be hampered by limits or


syntactic limitations present in even relationally full languages.

• External Data Sources: Additional language features or integration techniques may be


needed for queries using data from external sources, such as file systems or web services.

Consequently, it's important to take these practical limitations into account when assessing a
query language's expressiveness, even though relational completeness is a useful indicator of
its possibilities.

Question .6.) Explain sort-merge strategy in external sorting with the help of example.
Ans: Imagine an enormous library that is far too big to put on a single shelf and contains
millions of books. How would you effectively arrange them? External sorting uses the
sort-merge strategy, which is similar to a resourceful librarian's method of managing huge
datasets that require more RAM than is available.

This is the process, step-by-step:

1. Division into Runs: o The enormous dataset (library) is split up into more manageable,
smaller sections known as "runs." Consider them as separate bookcases.

o You can fit all of the books on one shelf since each run is small enough to fit into the
memory that is available.

2. Internal Sorting: o Using a conventional sorting algorithm, each run is sorted separately
(e.g., alphabetically sorting books on a shelf).

o The first sorting may be completed quickly and effectively in memory.

3. Merging Runs: o This is where the magic of sort-merge starts! Larger sorted runs are
produced by repeatedly merging sorted runs.

o Assemble two sorted shelves into one bigger shelf that is still sorted.

o Reading the first element from each run (looking at the first book on each shelf) is one step
in the merging process.

Placing the book in its proper location on the new shelf by choosing the smallest element and
putting it to the output file.

Reading the subsequent element (going to the next book on that shelf) from the run that
contained the smallest element.

Iterate until every component from both iterations is combined.

4. Iterative Merging: o Two sorted runs are combined to form a bigger sorted run. This is
how the merging process is carried out iteratively.

Next, this more extensive run is combined with an additional sorted run, and so on.

This produces sorted runs that get bigger and bigger until the whole dataset is sorted.

For illustration, let's say we need to sort a 900MB file utilising just 100MB of RAM.

o The file is split up into nine 100MB runs.

o Every run is internally sorted.

o By merging the nine sorted runs in pairs, four 200MB sorted runs total are produced.
o By merging these 4 runs in pairs, 2 sorted runs totaling 400 MB are produced.

o These two runs are combined at the end to produce a single, 900MB sorted file.

Principal

Benefits:

• Easily Manages Big Datasets: Sorts data that doesn't fit totally in memory.

• Capable of Adjusting to Limitations: Operates with restricted memory and storage capacity.

• Scalable: Only the amount of storage available restricts the size of datasets it can handle.

Extra Things to Think About:

Effective reading and writing from external storage devices is necessary for external storage.

• Optimization Methods: Methods such as multiway merging and replacement selection can
be used to further enhance the process.

You might also like