Dbs Final Note
Dbs Final Note
What is database?
In computing, a database is an organized collection of data stored and accessed
electronically. Small databases can be stored on a file system, while large databases are
hosted on computer clusters or cloud storage.
2
Components of a Database
1. Hardware
Hardware refers to the physical, electronic devices such as computers and hard disks that
offer the interface between computers and real-world systems.
3. Software
Software is a set of programs used to manage and control the database and includes the
database software, operating system, network software used to share the data with other
users, and the applications used to access the data.
3. Data
Data are raw facts and information that need to be organized and processed to make it
more meaningful. Database dictionaries are used to centralize, document, control, and
coordinate the use of data within an organization. A database is a repository of
information about a database (also called metadata).
3
4. Procedures
Database Access Language is a language used to write commands to access, update, and
delete data stored in a database. Users can write commands using Database Access
Language before submitting them to the database for execution. Through utilizing the
language, users can create new databases, tables, insert data, and delete data.
----------------------------Application of DBMS
The database keeps a record of ticket booking, arrival time, departure time, delays, and
even seat numbers of airplanes or trains.
3. Banking
An uncountable number of bank transactions and deposits are made, thousands of new
bank accounts are created daily, and many such things. This is all possible because of a
Database Management System that makes keeping track of the record much easier.
The details of each student, teacher, and even janitor are stored in a database to manage
the information easily.
Social media websites like Instagram, Facebook, Whatsapp, etc., are able to keep track of
each and every detail of their users (name, phone number, photos, email address,
password, etc.) with the help of Database Management Systems.
With time, more and more people have started shopping online, no one wants to go to a
shop and waste their time when they can do the same thing while at home and save time.
With the increase in online shopping customers, there's a need to store their details
efficiently.
That is why, all the details of the customers, products as well as order and tracking
details are stored and managed using a Database Management System.
Big companies have many employees, and their details and whereabouts are managed
by the Human Resource Management Department using DBMS.
8. Manufacturing
The products manufactured by companies have their details (quantity, amount, discount,
weight, etc.) stored using a Database Management System.
9. Telecommunication Sector
Ride-sharing, also known as carpooling uses DBMS to store the details of their
customers, drivers, and cars. The reviews of different drivers and the maps used by GPS
are also stored in databases using DBMS.
A real-time Database Management System is used to store and manage the details of the
patients, doctors, appointments, etc.
Research areas like AI, cancer treatment, molecular biology, and DNA sequencing are
some good examples of scientific research. All the research done to date has to be
stored in such a way that the database is secured and accessible to every researcher,
this is only possible because of a Database Management System.
5
------------------------------Levels of Data
1. Real World Data : The real world level of data means that level of data at which entities or
objects exist in reality, it means that any object existing in reality have a name and other
identifiable attributes through which we can identify that specific object or entity. Example:
Any Student
2. Meta Data: For storage of the data related to any entity or object existing at real world level
we define the way the data will be stored in the database. This is called Meta data. Meta data
is also known as schema for the real world data. It tells that what type of data will be stored
in the database, what will be size of a certain attribute of the real world data, how many and
what attributes will be used to store the data about the entity in the database. Example:
Name Character Type 25 character size field
Age Date type 8 bytes size
Class Alpha Numeric 8 byte size
Example 2: Let's consider a common example that you'll find in any relational database:
I have a table called AUTHOR. It contains data. I type "SELECT * FROM AUTHOR;" and the system lists
the contents of the AUTHOR records. This is data, just ordinary data -- Names, like "Joe" or "Sam", for
example.
Now I type "DESCRIBE AUTHOR;" and it displays this:
sql> DESCRIBE AUTHOR; or desc author;
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| A_ID | int(11) | | PRI | 0 | |
| A_FNAME | varchar(20) | YES | | NULL | |
| A_LNAME | varchar(20) | YES | MUL | NULL | |
| A_MNAME | varchar(20) | YES | | NULL | |
| A_DOB | date | YES | | NULL | |
| A_BIO | blob | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+ 6 rows in set
(0.00 sec)
This is metadata: It is data that describes other data. This data describes the format of other data, so
that it can be processed. Within the AUTHOR table is a column called A_FNAME. It may contain
5
values, like "Joe" or "Sam". That's data. In the relational database's "system tables" is more data, like
the string "A_FNAME".
3. Existence of Data: Existence of the data level shows the actual data regarding the entities as real
world level according to the rules define at the Meta Data level. Example: According to the definition
given in the Meta data level the Actual data or Data occurrence for the entity at real world level is
shown below:
Name Age Class
Rakib 20/8/1990 M.Sc
Amir 22/3/1991 B.Sc
6
For Example: Consider a program to transfer $500 from the account balance of department A to the
account balance of department B. If a system failure occurs during the execution of the program, it is
possible that the $500 was removed from the balance of department A but was not credited to the
balance of department B, resulting in an inconsistent database state. Clearly, it is essential to
database consistency that either both the credit and debit occur, or that neither occur. That is, the
funds transfer must be atomic—it must happen in its entirety or not at all. It is difficult to ensure
atomicity in a conventional file-processing system.
7. Concurrent-Access Anomalies
For the sake of overall performance of the system and faster response, many systems allow multiple
users to update the data simultaneously. Indeed, today, the largest Internet retailers may have
millions of accesses per day to their data by shoppers. In such an environment, interaction of
concurrent updates is possible and may result in inconsistent data. For example: Consider department
A, with an account balance of $10,000. If two department clerks debit the account balance (by say
$500 and $100, respectively) of department A at almost exactly the same time, the result of the
concurrent executions may leave the budget in an incorrect (or inconsistent) state. Suppose that the
programs executing on behalf of each withdrawal read the old balance, reduce that value by the
amount being withdrawn, and write the result back. If the two programs run concurrently, they may
both read the value $10,000, and write back $9500 and $9900, respectively. Depending on which one
writes the value last, the account balance of department A may contain either $9500 or $9900, rather
than the correct value of $9400.
8. Security Problems
Not every user of the database system should be able to access all the data. For example, in a
university, payroll personnel need to see only that part of the database that has financial information.
At the logical level these records can be described as fields and attributes along with their data types,
their relationship among each other can be logically implemented. The programmers generally work
at this level because they are aware of such things about database systems.
At view level, user just interact with system with the help of GUI and enter the details at the screen,
they are not aware of how the data is stored and what data is stored; such details are hidden from
them.
2. Schema and Instance
Definition of schema: The overall design of a database is called the schema. Schema is of three types:
Physical schema, logical schema and view schema.
a) Physical schema: The design of a database at physical level is called physical schema, how
the data stored in blocks of storage is described at this level.
b) Logical schema: Design of database at logical level is called logical schema, programmers
and database administrators work at this level, at this level data can be described as
Certain types of data records gets stored in data structures, however the internal details
such as implementation of data structure is hidden at this level (available at physical
level).
c) View schema: Design of database at view level is called view schema. This generally
describes end user interaction with database systems.
Definition of instance: The data stored in database at a particular moment of time is called instance of
database. Database schema defines the variable declarations in tables that belong to a particular
database; the value of these variables at a moment of time is called the instance of that database.
The ability to modify a schema definition in one level without affecting a schema definition in the next
level is called data independence.
There are two levels of data independence:
1. Physical Data Independence.
2. Logical Data Independence.
Physical Data Independence:
It is the ability to modify the physical schema without causing application programs to be rewritten.
Suppose there was a change in memory size of the database servers. This will not affect the logical
structure of any of the objects in the database. They are completely independent of the physical
structure. This is called physical data independence.
Logical Data Independence:
It is the ability to modify the logical schema without causing application program to be rewritten.
Logical data independence is more difficult than is the physical data independence.
Any changes to the database objects like changes to table structure, size or addition/removal of
columns from the table will not affect user views. They will see the data like before. This is called
logical data independence
There are two types of object based data Models – a) Entity Relationship Model and b) Object
oriented data model.
9
relationship set.
c. Relational Model
In relational model, the data and relationships are represented by collection of inter-related tables.
Each table is a group of column and rows, where column represents attribute of an entity and rows
represents records.
Multivalued Attributes: An attribute that can hold multiple values is known as multivalued attribute.
We represent it with double ellipses in an E-R Diagram. E.g. A person can have more than one phone
numbers so the phone number attribute is multivalued.
Derived Attribute: A derived attribute is one whose value is dynamic and derived from another
attribute. It is represented by dashed ellipses in an E-R Diagram. E.g. Person age is a derived attribute
as it changes over time and can be derived from another attribute (Date of birth).
----------------------------------------------------------------------------------------------------
Foreign Key – Foreign keys are the columns of a table that points to the primary key of another table.
They act as a cross-reference between tables.
-------------------------Database Users
The database users also can be categorized again into five groups according to how they interact with
the database. They are:
• Native Users
• Application Programmers
• Sophisticated Users
• Specialized Users
• Stand-alone Users
1. Native Users
These are the database users who are communicating with the database through an already written
program.
For example, when a student is registering on a website for an online examination. He creates data in
the database by entering and submitting his name, address and exam details.
2. Application Programmers
These are the software developers and programming professionals who write the program codes.
They use tools like Rapid Application Development (RAD) tools for creating user interfaces with
minimal efforts.
3. Sophisticated Users
Sophisticated users are those who are creating the database. These type of users do not write
program code. And they do not use any software to request the database.
The sophisticated users directly interact with the database system using query languages like SQL.
4. Specialized Users
The sophisticated users who write special database application programs are called specialized users.
The write complex programs for the specific complex requirements.
5. Stand-alone Users
Those who are using database of personal usage. There are many database packages for this type
database users.
11
--------------Database Administrators
The person who has the central control over a database system is called Database Administrator
(DBA).
The database administrator has the following functions in a database system.
-Schema Definition: The database administrator creates the original database schema by executing a
set of data definition statements in DDL.
-Storage structures an access method definition.
-Schema and physical or organization modification: The database administrator performs the changes
to the schema according to the needs of organizations or physical needs to improve the database
performance.
-Provide the granting of authorization to access data: The database administrator can decide the
which parts of the database can be accessed by a user, by using the different types of authorization
methods.
-Database maintenance: The database maintenance includes the following processes.
• Regular backing up of the database.
• Ensuring the disk space for performing the required operations.
• Monitoring the jobs running on the database.
I hope this article might be helped you for learning the Database Users and Administrators in DBMS.
SQL Commands
The standard SQL commands to interact with relational databases are CREATE, SELECT,
INSERT, UPDATE, DELETE and DROP. These commands can be classified into the following
groups based on their nature:
DDL - Data Definition Language
Command Description
CREATE Creates a new table, a view of a table, or other object in the database.
ALTER Modifies an existing database object, such as a table.
Deletes an entire table, a view of a table or other objects
DROP
in the database.
DML - Data Manipulation Language
Command Description
SELECT Retrieves certain records from one or more tables.
INSERT Creates a record.
UPDATE Modifies records.
12
Data Integrity
The following categories of data integrity exist with each RDBMS:
Entity Integrity: There are no duplicate rows in a table.
Domain Integrity: Enforces valid entries for a given column by restricting the type, the format, or
the range of values.
Referential integrity: Rows cannot be deleted, which are used by other records.
User-Defined Integrity: Enforces some specific business rules that do not fall into entity, domain or
referential integrity
char Varchar
Char datatype is used to store character Varchar datatype is used to store character
strings of fixed length. strings of variable length.
Char takes 1 byte space for each character. Varchar take 1 byte for each character along
with some extra bytes to store length
13
information.
We can use char datatype when we know the We can use it when we are not sure of the
length of the string. length of the string.
Char datatype can be used when we expect Varchar datatype can be used when we expect
the data values in a column to be of same the data values in a column to be of variable
length. length.
NCHAR vs NVARCHAR
The Transact-SQL date and time data types are listed in the following table:
2079-06-06
----------------------------------------------------------------------
Advantages of DBMS
• Controls database redundancy: All the data is stored in one place, and that
recorded in the database and hence controls the redundancy in the
database.
• Data sharing: DBMS allows users with authority to share the data in the
database with multiple users.
• Easy Maintenance: The centralized nature of the database helps in the easy
maintenance of the data.
• Reduce time: It reduces the maintenance need and development time.
• Backup: It automatically backs up data to maintain its integrity in case of
failure.
• Multiple user interfaces: It offers a number of user interface to multiple
users.
Disadvantages of DBMS
1. Attribute: Each column in a Table. Attributes are the properties which define a
relation. e.g., Student_Rollno, NAME,etc.
2. Tables – In the Relational model the, relations are saved in the table format. It is
stored along with its entities. A table has two properties rows and columns. Rows
represent records and columns represent attributes.
3. Tuple – It is nothing but a single row of a table, which contains a single record.
4. Relation Schema: A relation schema represents the name of the relation with its
attributes.
5. Degree: The total number of attributes which in the relation is called the degree of
the relation.
17
Constraints can be specified when the table is created with the CREATE
TABLE statement, or after the table is created with the ALTER
TABLE statement.
Syntax
CREATE TABLE table_name (
column1 datatype constraint,
column2 datatype constraint,
column3 datatype constraint,
....
);
Data integrity means the data has been collected and stored accurately, as well as
being contextually accurate to the model at hand. To maintain integrity, data must
be collected and stored in an ethical, law-abiding way and must have a complete
structure where all defining characteristics are correct and can be validated.
PHYSICAL INTEGRITY
Many companies outsource their data storage to cloud providers, such as AWS, to
manage the physical integrity of the data. This is particularly useful for small
companies that benefit from offloading data storage to spend more time focusing
on their business.
• Entity integrity
• Referential integrity
• Domain integrity
• User-defined integrity
Entity integrity involves the creation of primary keys to identify data as distinct
entities and ensure that no data is listed more than once or is null. This allows data
to be linked to and enables its usage in a variety of ways.
Referential integrity is the series of processes that is used to store and access data
uniformly, which allows rules to be embedded into a database’s structure
regarding the use of foreign keys. This allows for a consistent and meaningful
combination of data sets across the database. Critically, referential integrity allows
the ability to combine various tables within a relational database, facilitating
uniform insertion and deletion practices.
Domain integrity refers to the collection of processes that ensure accuracy in each
piece of data included in a domain, or a set of acceptable values that a column may
contain.
User-defined integrity provides rules and constraints that are created by the user
in order to use data for their specific purpose.
• CREATE INDEX - Used to create and retrieve data from the database
very quickly