Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
A Database Management System (DBMS) is basically a collection of programs that enables users to store,
modify, and extract information from a database as per the requirements. DBMS is an intermediate layer
between programs and the data. Programs access the DBMS, which then accesses the data. There are
different types of DBMS ranging from small systems that run on personal computers to huge systems that
run on mainframes.
Advantages of DBMS
The database management system has a number of advantages as compared to traditional computer file-
based processing approach. The DBA must keep in mind these benefits or capabilities during databases and
monitoring the DBMS.
The Main advantages of DBMS are described below.
Data Independence
Backup and Recovery Procedures
Control Over Concurrency
Report Writers
Data Security
Integration Constraints
Integration of Data
Data Consistency
Sharing of Data
Controlling Data Redundancy
1. A database management system coordinates both the physical and the logical access to the data, whereas a
file-processing system coordinates only the physical access.
2. A database management system reduces the amount of data duplication by ensuring that a physical piece
of data is available to all programs authorized to have access to it, whereas data written by one program in a
file-processing system may not be readable by another program.
3. A database management system is designed to allow flexible access to data (i.e., queries), whereas a file-
processing system is designed to allow predetermined access to data (i.e., compiled programs).
4. A database management system is designed to coordinate multiple users accessing the same data at the
same time. A file-processing system is usually designed to allow one or more programs to access different
data files at the same time. In a file-processing system, a file can be accessed by two programs concurrently
only if both programs have read-only access to the file.
7. DBMS provide back up and recovery. When data is lost in file system then it not recover.
8. DBMS provide multiple user interfaces. Data is isolated in file system,
Q3. Describe the three levels of data abstraction? What is Data Independence?
Data are actually stored as bits, or numbers and strings, but it is difficult to work with data at this level.It is
necessary to view data at different levels of abstraction.
Schema:
Description of data at some level. Each level has its own schema.
physical,
conceptual, and
external.
A View is a "Virtual Table". It is not like a simple table, but is a virtual table which contains columns and
data from different tables (may be one or more tables). A View does not contain any data, it is a set of
queries that are applied to one or more tables that is stored within the database as an object. After creating a
view from some table(s), it used as a reference of those tables and when executed, it shows only those data
which are already mentioned in the query during the creation of the View.
As view does not depend on data, it only depend upon underlying table, it is called as data independent.
A view may be thought of as a virtual table, that is, a table that does not really exist in its own right but is
instead derived from one or more underlying base table. In other words, there is no stored file that direct
represents the view instead a definition of view is stored in data dictionary.
Growth and restructuring of base tables is not reflected in views. Thus the view can insulate users from
the effects of restructuring and growth in the database. Hence accounts for logical data independence.
Data Model:
The structure of database is the data model. A collection of conceptual tools for describing data, data
relationships, data semantics and consistency constraints. The Entity-Relationship model and the relational
model. Both provide a way to describe the design of a database at the logical level.
• A structural part, consisting of a set of rules according to which databases can be constructed.
• A manipulative part, defining the types of operation that are allowed on the data (this includes the
operations that are used for updating or retrieving data from the database and for changing the structure of
the database).
• Possibly a set of integrity rules, which ensures that the data is accurate.
The Entity-Relationship (E-R) data model is based on a perception of a real world that consists of a
collection of basic objects, called entities, and of relationships among these objects. An entity is a “thing” or
“object” in the real world that is distinguishable from other objects. For example, each person is an entity,
and bank accounts can be considered as entities.
Entities are described in a database by a set of attributes. For example, the attributes account-number and
balance may describe one particular account in a bank, and they form attributes of the account entity set.
Similarly, attributes customer-name, customer-street address and customer-city may describe a customer
entity.
A relationship is an association among several entities. For example, a depositor relationship associates a
customer with each account that she has. The set of all entities of the same type and the set of all
relationships of the same type are termed an entity set and relationship set, respectively.
The overall logical structure (schema) of a database can be expressed graphically by an E-R diagram, which
is built up from the following components:
Functional dependency is a relationship that exists when one attribute uniquely determines another attribute.
If R is a relation with attributes X and Y, a functional dependency between the attributes is represented as X-
>Y, which specifies Y is functionally dependent on X. Here X is a determinant set and Y is a dependent
attribute. Each value of X is associated precisely with one Y value.
Functional dependency in a database serves as a constraint between two sets of attributes. Defining
functional dependency is an important part of relational database design and contributes to aspect
normalization.
As per First Normal Form, no two Rows of data must contain repeating group of information i.e each set of
column must have a unique value, such that multiple columns cannot be used to fetch the same row. Each
table should be organized into rows, and each row should have a primary key that distinguishes it as unique.
Second Normal Form (2NF)
As per the Second Normal Form there must not be any partial dependency of any column on primary key. It
means that for a table that has concatenated primary key, each column in the table that is not part of the
primary key must depend upon the entire concatenated key for its existence. If any column depends only on
one part of the concatenated key, then the table fails Second normal form.
Third Normal Form (3NF)
Third Normal form applies that every non-prime attribute of table must be dependent on primary key, or
we can say that, there should not be the case that a non-prime attribute is determined by another non-prime
attribute. So this transitive functional dependency should be removed from the table and also the table must
be in Second Normal form. For example, consider a table with following fields.
Boyce and Codd Normal Form (BCNF)
Boyce and Codd Normal Form is a higher version of the Third Normal form. This form deals with certain
type of anamoly that is not handled by 3NF. A 3NF table which does not have multiple overlapping
candidate keys is said to be in BCNF. For a table to be in BCNF, following conditions must be satisfied:
Sql Statements are used to retrieve data from the database. We can get same results by writing different
sql queries. But use of the best query is important when performance is considered. So you need to sql
query tuning based on the requirement. Here is the list of queries which we use reqularly and how these
sql queries can be optimized for better performance.
SQL Tuning/SQL Optimization Techniques:
1) The sql query becomes faster if you use the actual columns names in SELECT statement instead of
than '*'.
For Example: Write the query as
SELECT id, first_name, last_name, age, subject FROM student_details;
Instead of:
DBMS RDBMS
1) DBMS applications store data as RDBMS applications store data in a tabular form.
file.
2) In DBMS, data is generally stored In RDBMS, the tables have an identifier called primary key
in either a hierarchical form or a and the data values are stored in the form of tables.
navigational form.
3) Normalization is not present in Normalization is present in RDBMS.
DBMS.
4) DBMS does not apply any RDBMS defines the integrity constraint for the purpose
security with regards to data of ACID (Atomocity, Consistency, Isolation and
manipulation. Durability) property.
5) DBMS uses file system to store in RDBMS, data values are stored in the form of tables, so
data, so there will be no relation arelationship between these data values will be stored in
between the tables. the form of a table as well.
6) DBMS has to provide some RDBMS system supports a tabular structure of the data and
uniform methods to access the a relationship between them to access the stored
stored information. information.
7) DBMS does not support RDBMS supports distributed database.
distributed database.
8) DBMS is meant to be for small RDBMS is designed to handle large amount of data. it
organization and deal with small supportsmultiple users.
data. it supports single user.
9) Examples of DBMS are file Example of RDBMS are mysql, postgre, sql
systems, xml etc. server, oracle etc.
The create table command defines each column of the table uniquely. Each column has minimum of three attributes.
Name
Data type
Size(column width).
Each table column definition is a single clause in the create table syntax. Each table column definition is separated
from the other by a comma. Finally, the SQL statement is terminated with a semicolon.
The DROP Command
Syntax:
DROP TABLE <table_name>
Example:
DROP TABLE Student;
It will destroy the table and all data which will be recorded in it.
The TRUNCATE Command
Syntax:
TRUNCATE TABLE <Table_name>
Example:
TRUNCATE TABLE Student;
The RENAME Command
Syntax:
RENAME <OldTableName> TO <NewTableName>
Example:
RENAME <Student> TO <Stu>
The old name table was Student now new name is the Stu.
By The use of ALTER TABLE Command we can modify our exiting table.
Syntax:
ALTER TABLE <table_name>
ADD (<NewColumnName> <Data_Type>(<size>),......n)
Example:
ALTER TABLE Student ADD (Age number(2), Marks number(3));
The Student table is already exist and then we added two more columns Age and Marks respectively, by the use of
above command.
DML command
Data Manipulation Language (DML) statements are used for managing data in database. DML commands
are not auto-committed. It means changes made by DML command are not permanent to database, it can be
rolled back.
1) INSERT command
Insert command is used to insert data into a table. Following is its general syntax,
INSERT into table-name values(data1,data2,..)
INSERT into Student values(101,'Adam',15);
2) UPDATE command
Update command is used to update a row of a table. Following is its general syntax,
UPDATE table-name set column-name = value where condition;
3) Delete command
Delete command is used to delete data from a table. Delete command can also be used with condition to
delete a particular row. Following is its general syntax,
DELETE from table-name;
The above command will delete all the records from Student table.
Database administration is more of an operational or technical level function responsible for physical
database design, security enforcement, and database performance. Tasks include maintaining the data
dictionary, monitoring performance, and enforcing organizational standards and security.
Super Key – An attribute or a combination of attribute that is used to identify the records uniquely is known
as Super Key. A table can have many Super Keys.
E.g. of Super Key
1 ID
2 ID, Name
3 ID, Address
4 ID, Department_ID
5 ID, Salary
6 Name, Address
7 Name, Address, Department_ID ………… So on as any combination which can identify the records
uniquely will be a Super Key.
(II) Candidate Key – It can be defined as minimal Super Key or irreducible Super Key. In other words an
attribute or a combination of attribute that identifies the record uniquely but none of its proper subsets can
identify the records uniquely.
E.g. of Candidate Key
1 Code
2 Name, Address
For above table we have only two Candidate Keys (i.e. Irreducible Super Key) used to identify the records
from the table uniquely. Code Key can identify the record uniquely and similarly combination of Name and
Address can identify the record uniquely, but neither Name nor Address can be used to identify the records
uniquely as it might be possible that we have two employees with similar name or two employees from the
same house.
(III) Primary Key – A Candidate Key that is used by the database designer for unique identification of each
row in a table is known as Primary Key. A Primary Key can consist of one or more attributes of a table.
E.g. of Primary Key - Database designer can use one of the Candidate Key as a Primary Key. In this case
we have “Code” and “Name, Address” as Candidate Key, we will consider “Code” Key as a Primary Key as
the other key is the combination of more than one attribute.
(IV) Foreign Key – A foreign key is an attribute or combination of attribute in one base table that points to
the candidate key (generally it is the primary key) of another table. The purpose of the foreign key is to
ensure referential integrity of the data i.e. only values that are supposed to appear in the database are
permitted.
E.g. of Foreign Key – Let consider we have another table i.e. Department Table with Attributes
“Department_ID”, “Department_Name”, “Manager_ID”, ”Location_ID” with Department_ID as an Primary
Key. Now the Department_ID attribute of Employee Table (dependent or child table) can be defined as the
Foreign Key as it can reference to the Department_ID attribute of the Departments table (the referenced or
parent table), a Foreign Key value must match an existing value in the parent table or be NULL.
(V) Composite Key – If we use multiple attributes to create a Primary Key then that Primary Key is called
Composite Key (also called a Compound Key or Concatenated Key).
E.g. of Composite Key, if we have used “Name, Address” as a Primary Key then it will be our Composite
Key.
(VI) Alternate Key – Alternate Key can be any of the Candidate Keys except for the Primary Key.
E.g. of Alternate Key is “Name, Address” as it is the only other Candidate Key which is not a Primary Key.
(VII) Secondary Key – The attributes that are not even the Super Key but can be still used for identification
of records (not unique) are known as Secondary Key.
E.g. of Secondary Key can be Name, Address, Salary, Department_ID etc. as they can identify the records
but they might not be unique.