Database
Database
Class XII – Computer Science – is called a record. Let us see one student’s biographic information (record) :
Roll Number 13-3101
Notes Student Name Muhammad Saleem
Class XI
Practicals File : A collection of related records treated as a single unit is called a file or a data
set. Records of all the students together, make a file.
1 2
Savings A/C
Automobile loan
Personal loan
Clients biographic information etc.
The bank’s clients / customer database would include records from each of these files.
Using a series of programs, data for any client may be added, retrieved or updated
depending upon the activity at a particular time. The user of the database normally has
following facilities :
Adding new, blank files to the database.
Relational Model : Collection of simple files/Relations (Entities), each of which has
Inserting new data into the existing files.
no structural or physical connection like hierarchical or network systems. The various
Retrieving data from existing files.
entities possess the interrelationships as depicted by a network like diagram but these
Updating data in existing files.
relationships are based on the data content of the entities involved.
Deleting data from existing files.
Removing existing files, empty or otherwise from the database.
3 4
which allow various ways to logically access the data. the query is in the form of a sentence or English-like command i.e., SELECT,
Sophisticated Data Security Features : Provide enhanced security mechanisms for DELETE, CREATE, MODIFY, UPDATE and INSERT commands.
access to data. Data base security mechanisms typically go much further in adding Report Generator : A report generator is a program that is used to produce an on-
more extensive security features. screen or printed document from the database. The report format can be specified in
Data Base Backup / Recovery : Provide sophisticated backup / recovery mechanism. advance i.e., row headings, column headings, page headers etc. Even the non-experts
Backup / Recovery capabilities often distinguish between true DBMS and a software can create very useful and attractive reports by using this facility.
package that only claims this facility. Access Security : By using this facility, the database administrators can assign
Advanced Capabilities : DBMS normally have advance access capability for on-line specific access privileges for the users of the databases.
and ad-hoc reporting capabilities. Backup and Recovery : It is an important feature available in almost all the DBMS
programs. By using this feature, we are able to have the backup of our data and can
Q : 01-03-03 : Describe Disadvantages of Database Management later, use it to reinstate it in case of data failure, corruption or loss.
System (DBMS) ?
Answer :
Disadvantages of Database Systems :
Require additional System Overhead : Additional overhead is required to access
data, in case of doing some simple jobs; like reading and processing a tape file, which
might take a little time and resources to do the job. If we have to do it on DBMS, it is
like “requiring too much to do too little”.
Additional Training Required for Training of Staff : Application programmers
require a sort of precise training to code efficient programs that will run under a
DBMS.
Problems can multiply in selecting a wrong type of Database Environment : A
later change in structure, forced by changing requirements, can be costly in terms of
conversion and testing of existing programs.
Data must be considered a Corporate Resource : The data in a company’s database
no longer belong to one organization alone. One organization normally has the
primary responsibility for creating a database, many can share the same data across
applications.
A Need of a Dictionary : To share data across application systems, the internal data
contents of a company’s databases need to be documented in a consistent manner, thus
another overhead on the DBMS.
5 6
Q : 02-03-02 : Describe Properties of Relation ?
Chapter 02 : Basic Concepts & Terminology of Answer :
Databases Properties of Relation : A Relation or a Table which is the basis of a Relational
DBMS, by definition must have certain inherent characteristics that form the basic for
2.1 Overview its underlying strength and flexibility. Because of these features, an application
implemented by using such a system is much more flexible and can be easily modified
Q : 02-01-01 : Define Field, Record and File ? when alterations or enhancements to the underlying data base take place. These
Answer : characteristics are :
Field : A field is a unit of data consisting of one or more characters i.e., Roll Number, No Duplicate Rows Exist : No two rows can be identical. Why to put two rows
Student Name, Grade etc. (records) for the same entity (i.e. person). It will also violate the definition of what a
Record : A collection of related data items treated as a single unit is called a record. relation represents, as it says by definition that their must be a unique key for each row
File : A collection of related records treated as a single unit is called a file or a data in a relation / table.
set. The Order of Rows is Insignificant : There is no ordering or sequencing of the rows
in the tables. The relational implementation of the tables support all required access
2.2 Attributes, Rows and Tables mechanism i.e., it is not necessary to sequence the rows according to the key field.
The Order of Columns is Insignificant : Again, the order of the columns/attributes
Q : 02-02-01 : Define Data Elements, Records, Files or Datasets and in defining a relation/table has no significance. The later insertions of the columns are
Databases ? made at end of the existing columns by the system itself. The system acquires the data
Answer : (of columns) by their names.
Data Elements : The fields or data items in databases are termed as data items, items, Columns / Attributes are all Elemental or Atomic : All the intersections of Rows
attributes or columns in database structures. and Columns must have a nulls are inserted by the system at the time of column,
Records : Records in file management structures are termed as rows or tuples in which should immediately be replaced by zeros / spaces valid values for that particular
database structures. column.
Files or Datasets : Files or Datasets in databases are termed as tables relations or data
objects in database structures. 2.4 Views
Database : The collection of tables with some traditional files and some other
necessary data objects is termed as a database. Q : 02-04-01 : Describe Views ?
Answer :
2.3 Relation or Table Views : Views are created by using SQL, which is a powerful database language, used
for data definition and data manipulation purposes. The purpose of using views is
Q : 02-03-01 : Define Relation or Table and describe Entity ? purely to keep the data safe and secure from un-authorized and illegal users. The
Answer : views provide the descriptions of relations that are not stored, but constructed as
Relation or Table : A two dimensional array or table of data containing descriptive needed from stored relations. To create a view, normally the following CREATE SQL
information about an entity. The entity must have a unique identifier, which is command is used :
composed of a combination of one or more attributes, and each attribute must have CREATE VIEW STUDENT_VIEW_01 AS
one and only one value. It is appropriate to define the word Entity here. SELECT STUDENT_NO, STUDENT_NAME,
Entity : An entity is any thing about which you want to keep information in the STUDENT_ADDRESS
database: Let us consider an example of “Student Information System”, which has FROM STUDENT
entities like student, teacher, course list, scholarships, time-tabling. Thus, the entities WHERE STUDENT_GENDER_CD = “M”;
involved in this case are the same and the entity “student” can be defined in the form This will create a view from the STUDENT table for only male students, which can be
of database modeling : used by the users according to the authorization given to them, leaving the original
STUDENT (STUDENT_NO, STUDENT_NAME, STUDENT_GENDER_CD, table aside, safe and secure.
STUDENT_BIRTH_DATE, STUDENT_ADDRESS, STUDENT_TEL_NO)
From the above given definition of entity, we can easily construct a two- dimensional 2.5 Indexes
array or a relation by converting all the attributes in the brackets into columns of the
array. Q : 02-05-01 : Describe Indexes ?
Answer :
7 8
Indexes : It is another table created by the system developer / DBA containing the key the computer systems, but instead, he should be aware of the installed software he
attributes of the table for which the Index is created. It has a very vital role in the intends to use.
database management systems, especially in RDBMS. The important associations
defined in the system make use of this. It helps the system run smooth and fast. 2.8 The Data Administrator
9 10
Cardinality : Whether some occurrence(s) of object-1 are related to some
Chapter 03 : Database Design Process occurrence(s) of object-2. It is expressed as one or many. A relationships can be One
to One, One to Many, Many to Many, Recursive and None.
3.1 Overview
Modality : It defines the nature of the relationship :
Optional …….. represented by 0
Q : 03-01-01 : Define Feasibility Study, Requirements Analysis,
Mandatory …….. represented by 1
Project Planning and Data Analysis ?
Consider two objects Customer and Repair Action in a Workshop environment :
Answer :
Feasibility Study : This is also called preliminary investigation of the required
database. It involves the area identification and selection i.e. which area or aspect is to
be selected to start with. After the project is selected, it is allocated a specific find and
a proper planning is chalked out for its practical implementation. Side by side, a
proper market analysis is also worked out.
Requirements Analysis : During this activity, the requirements are gathered i.e. the
possible inputs for the database and the required functionality out of it. The users
precisely narrate their needs of the database and the possible domain and restrictions
are also chalked out.
Project Planning : A proper schedule is laid down to accomplish this activity. All the
cost factors are taken into consideration i.e., the salaries of team members, theft
logistics involved, other trivial expenses (such as marriage gifts, insurances etc) and
hardware costs.
Data Analysis : This is an important analysis aspect while designing a database. It
involves :
Data Flow Diagrams (DFD)
Decision Tables A simple Data Model can be drawn from the above as :
Decision Trees
13 14
Answer :
Physical Database Design : [To implement the database as a set of stored records,
files, indexes and other data structures that will provide adequate performance and
ensure database integrity, security and recoverability].
There are three major inputs to Physical database design :
Logical Database Structures : Developed during logical database design i.e.,
the Normalized Relations.
User Processing Requirements : The size and frequency of use of the Data-
Base, response time, security, backup, recovery etc.
Characteristics of the DBMS and other components of the computer Operating
environment.
15 16
High throughput for processing transactions.
Efficient use of storage space.
Chapter 04 : Data Integrity and Normalization
Protection from failure or data loss.
4.1 Overview
Minimizing need for re-organization.
Accommodating growth.
Q : 04-01-01 : Explain Data Integrity ?
Security from un-authorized use.
Answer :
Indexes : An index is a table that is used to determine the location of rows in a table (
Data Integrity : Database integrity refers to the correctness and consistency of data. It
or tables) that satis1’ some condition. They may be created on primary key, secondary
is another form of database protection. While it is related to security and precision, it
key, foreign key etc.
has some broader implications as well. Security involves protecting the data from
Integrity Constraints : Database integrity refers to the correctness and consistency of
unauthorized operations, while integrity is concerned with the quality of data itself.
data. It is another form of database protection. While it is related to security and
Integrity is usually expressed in terms of certain constraints which are the consistency
precision, it has some broader implications. Security involves protecting the data from
rules that the database is not permitted to violate. Following two are the most
unauthorized operations, while integrity is concerned with the quality of data itself
important constraints in relational databases :
Integrity is usually expressed in terms of certain constraints which are the consistency
Entity Integrity : It is a constraint on primary values that states that no
rules that the database is not permitted to violate.
attribute of a primary key should contain nulls.
Referential Integrity : It is a constraint on foreign key values that states
3.4 Implementation
that if a foreign key exists in a relation, then either the foreign key value
must match the primary key value of some tuple in its home relation or
Q : 03-04-01 : Explain Database Implementation Phase ?
the foreign key value must be completely null.
Answer :
Database Implementation Phase : The builder or the database administrator
Q : 04-01-02 : Explain Normalization ?
normally requires a server computer which will be linked with hundreds and
Answer :
thousands of computer users who would want to share and interact with the server
Normalization : [It is the process of converting complex data structures into simple
(database). For this purpose, the DBA might need the services of network
and stable data structures. It is based on the analysis of functional dependence].
administrators to connect the users with the server. The users are normally given the
[Normalization is a technique for reviewing the entity / attribute lists to ensure that
authorizations / permissions defined by their respective managers so that they can
attributes are stored “where they belong to”. It is the basis for a relational data base
perform the authorized tasks while using the database facilities. In distributed
system]. In practice, it is simply an applied common sense. More formally stated, [it is
computing environment, the database servers and users might be thousands of
the process of analyzing the dependencies of attributes within entities. Attributes for
kilometers apart, so a lot of expensive telecommunication links are required to
each entity are checked consecutively against three sets of rules, making adjustments
perform the designated tasks. NADRA and CRICKINFO are some of the typical
when necessary to put the entity in First, Second and Third normal form].
examples of this type of databases.
“A functional dependency is a particular relationship between two attributes. For any
relation R, attribute B is functionally dependent on attribute A if, for every valid
instance of A, that value of A uniquely determines the value of B” The functional
dependence of B on A is represented by an arrow. An attribute may be functionally
dependent on two or more attributes rather than a single attribute. There may be some
hidden problems as :
Synonyms : A synonym is created when two different names are Used for the same
information (attribute). If an attribute resides in more than one entity, make sure that
all entities use the same attribute name.
Homonyms : A homonym is created when same name is used for Two different
attributes. Redundant Information : Storing the same information in two different
ways or forms if only one attribute can serve the purpose.
Mutually Exclusive Data : Mutually exclusive data exists when attributes occur whose values can
be expressed as “YES/NO” indicators, can not all be true for any single entity.
Normalization is often accomplished in steps, each of which corresponds to a normal
form. It can be graphically expressed as :
17 18
Q : 04-01-04 : Explain Second Normal Form (2 NF) ?
Answer :
Second Normal Form (2 NF) : [A relation is in second normal form NF (2 NF) if it is
in 1 NF and every non-key attribute is fully functionally dependent on the primary
key].
Second Definition : “To be in 2 NF, every non-key attribute must depend on
the key and all parts of the key”.
Necessary & Sufficient Conditions : A table (relation) will be in 2NF if any of
the following conditions apply :
The primary key consists of only one attribute.
No non-key attributes exist in the relation.
Q : 04-01-03 : Define Normalization and Normal Form ? Every non-key attribute is functionally dependant on the full set of
Explain First Normal Form (1 NF) ? primary key attributes.
Answer :
Normalization : [It is the process of converting complex data structures into simple Consider table STUDENT in shorthand notation :
and stable data structures. It is based on the analysis of functional dependence]. STUDENT(STUD-ID,NAME,DEPT,MONFEE,CRSNO,CDTE)
[Normalization is a technique for reviewing the entity / attribute lists to ensure that The functional dependencies in this relation are the as follows :
attributes are stored “where they belong to”. It is the basis for a relational data base STUD-ID NAME, DEPT, MONFEE
system]. STUD-ID,CRSNO CDTE
Normal Form : A Normal Form is a state of a relation that can be determined by The primary key in ii above is the composite key :
applying simple rules, regarding dependencies (or relationship between attributes), to STUD-ID + CRSNO.
that relation. Therefore, the non-key attributes NAME,DEPT and MONFEE are
First Normal Form (1 NF) : “A relation R is in First Normal Form if and only if all functionally dependent on part of the primary key (STUD-ID) but not on
underlying domains contain atomic values only”. CRSNO.
Relation : The Pre-Requisite is that “A relation has always a primary key Partial Functional Dependency : [A partial functional dependency exists when
associated with it”. one or more non-key attributes (such as NAME) are functionally dependant on
Unique Identification Key : All entities must have a key, composed of a part (but not all) of the primary key].
combination of one or more attributes which uniquely identify one Anomalies : The partial functional dependency creates redundancy in the table,
occurrence of the entity. which results in certain anomalies when the table is updated :
No Repeating Groups : For any single occurrence of an entity, each Insertion Anomaly : To insert a row for the table, we must provide the
attribute must have one and only one value or “An attribute must have no values for both STUDENT-ID (Primary Key) and COURSE-NO (Not
REPEATING GROUPS”. Primary Key).
Step-1 : Whenever repeating groups occur, the repeating Attribute must be Deletion Anomaly : If we delete a row for one student, we lose the
removed and placed “Where it Belongs”, under the entity that it describes. information that the student completed a course on a particular date.
Step-2 : Next, study the relationship of where the Repeating attribute came Modification Anomaly : If a students monthly fee changes, we must
from, and where the Attribute went to. Determine if the From-To Relationship record the change in multiple rows (for students, who have completed
is 1:M or M:N. more than one course).
19 20
Important Note : To convert a relation to 2 NF, we decompose the relation Insertion Anomaly : A new salesman (Abid), assigned to the North region can not be
(having redundant data) into two relations that satisfy one of the conditions entered until a customer has been assigned to that salesman (since a value of
described above. Now, by splitting the relation, we will get two relations. This CUSTNO must be provided to insert a row in the table(relation).
step is done to get rid of the redundant data. Anomalies are removed at the end Deletion Anomaly. If customer number 6837 is deleted from the relation, we lose the
of 2 NF. information that salesman Khalid is assigned to the east region.
Modification Anomaly : If salesman Ahmad is assigned to the east region, several
Q : 04-01-05 : Explain Third Normal Form (3 NF) and rows must be
Transitive Dependency ? changed to reflect the fact (two rows in this case).
Answer : These anomalies arise as a result of the transitive dependency. This problem (the
Third Normal Form (3 NF) : [A relation is in third normal form (3 NF) if it is in 2 transitive dependency) can be removed by de-composing the relation SALES into two
NF and no transitive dependencies exist]. relations as shown below:
Transitive Dependency : [It is a functional dependency in a relation between two or
more non-key attributes].
Third Normal Form (3 NF) – Second Definition : A more precise definition for 3
NF is :
“A non-key attribute must not depend on any other non-key attribute” or “if a non- key
attribute’s value can be obtained simply by knowing the value of another non-key
attribute, the relation is not in
3 NF. The Anomalies, Insertion Anomaly, Deletion Anomaly and Modification
Anomaly must be related with example data. These anomalies arise as a result of the and
transitive dependency. This problem (the transitive dependency) can be removed by
de-composing the a relation into two relations.
The Anomalies
21 22
Q : 05-04-01 : Describe MS Access Database Components ?
Chapter 05 : Introduction To Microsoft Access Answer :
Microsoft Access Database Components : MS-Access database consists of various
5.1 Overview
components called the objects. The database objects are used to store data and to
retrieve data from database. The major database objects are :
Q : 05-01-01 : Describe MS Access ? Describe Benefits of MS
Tables : The most important object of a database is a Table. The data is stored
Access ?
in tables of database. A table is a collection of related data organized in rows
Answer :
and, columns. Each row consist a record, and each record consists of columns.
Microsoft Access : Microsoft Access is one of the most popular and powerful DBMS.
The row is divided into columns called field containing different data values of
It has many built in features to assist you in constructing database and viewing
a particular record. A relational database may contain multiple tables, which are
information. MS Access is much more involved and is a more genuine DBMS than
identified by unique names. This is the fundamental property of a relational
other programs such as Microsoft Works. Microsoft Access is a Relational Database
database.
Management System (RDBMS) that you can use to store and manipulate large amount
Queries : Query is a statement that extracts specific information from database.
of information. It is easy to understand and its graphical interface, helps to create
It is created by specifying the fields to display from a table or another query. It
queries, forms, and reports. In other words, even inexperienced programmers can use
is more flexible way of selecting, filtering and sorting records. The user can also
MS Access to turn a stack of invoices, a card file of customer names, a ledger, and an
change data in the database that fulfils certain criteria. In addition, queries allow
inventory list into a relational database that makes entering, updating, and reporting
to perform calculations of different fields. The output of a query is also
information as easy as clicking a button.
displayed in the form of a table and can also be used as source of records for
Benefits of Microsoft Access : MS-Access offers more than just pretty interface for
Forms and Reports. The query allows you to view and analyze data in many
learning how to manage data. Benefits of MS Access are :
different ways. Technically, a query is a stored question or request. You design
Sample Databases : It includes sample database applications to assist you learn
a query in design view to extract certain information from the database. The
about real-world tables, forms, queries, and reports, and how they are
information appears in Datasheet which looks exactly like Datasheet view for a
interconnected to form a database management system.
table. The difference between a datasheet for a table and a datasheet for a query
Wizard : It makes very easy to create a database. You can choose from several
is that the query’s datasheet can combine information from multiple tables.
examples of databases in the Database Wizard for such storage uses as contact
Forms : The Form object of database is used to enter data into databases, edit
information, inventory control, a ledger, and so on. You can create and then
data and view data from database. You can add, update, and delete records in
modi1r these databases to meet your own needs.
your table by using a form. Form provide :
Keys to Understand The Structure : After you have decided how to create and
An easy method for entering and editing data in tables. Thus the user does not
relate tables, you can easily view all the relationships in the database with the
have to work directly with tables.
graphical interface in the Relationship Window. This makes one of the toughest
Facilities to display data retrieved from database tables.
parts of relational database design much easier and more manageable.
Most of the DBMSs provide the facility to create Forms. The application
Microsoft Office Integration : You can use access with Word, Excel, and other
programmer creates the user interface by designing the Forms. In this way arid
office application to create mail merges, charts, and other helpful uses for your
Reports, the users can perform different operations on the database very easily.
data.
Reports : The Report object of database is used to retrieve and present data in a
Easier Programming : You can use relatively simple code with macros to
formatted way. The Report can be printed. Some reports are simply a list of the
automate repeated tasks, or you can try more complex and flexible code with
records in the database, one record after the other. Most of the popular DBMS
VBA. Access provides graphical shortcuts and hints to help writing easier code.
provide this facility. The output of the query can also be given as input source to
Common Standards : It uses standards that help applications scale up to work
Reports.
within larger environments. Access uses objects and SQL (Structure Query
The Difference Between The Forms and Report :
Language) to make its code from the adaptable to other applications.
Forms are used to enter data into database, change data and view data of
Redundancy : MS-Access allows you to store, retrieve, sort, analyze, and print
databases.
information contained in the database. Data may be manipulated without data
Reports are used to retrieve the data from database and present it on screen in a
redundancy by defining relationships between sets of data. Databases are often
predefined format. Reports do not allow user to change data or to enter data into
used for product data. Redundancy means duplication of data in multiple files. It
database.
wastes the storage media of computer.
25 26
Date / Time - A Date, Time, or combination of both can be specified in this field. Update Queries : An update query makes changes to a gr of records in one or
Currency - Monetary values that can be set up to automatically include a dollar sign more tables.
($) and correct decimal and comma positions. Append Queries : An append query adds a group of records from one or more
Auto Number - When a new record is created, Access will automatically assign a tables to the end of one or more tables.
unique integer to the record in this field. Crosstab Queries : There are crosstab queries to calculate and restructure data
Yes / No - Use this option for True / False, Yes / No, On / Off, or other values that for easier analysis of your data. Crosstab queries calculate a sum, average,
must be only one of two choices. count, or other type computation for data. These queries are grouped by two
OLE Object - An OLE (Object Linking and Embedding) object is a sound, picture, or types of information, one down the left side of the datasheet and another across
other object such as a Word document or Excel spreadsheet that is created in another the top.
program. Use this data type to embed an OLE object or link to the object in the Parameter Query
database. A parameter query is a query that when run displays its own dialog and prompting you
Hyper link - A hyperlink will link to a website, or another location in tbe database. A for information. Parameter queries are also used as the basis for forms and reports.
hyperlink address have up to four parts: the text that is displayed in the field; the path
to a file or URL; a sub-address which is a location in the file or page in the web site;
and the text that is displayed as the tool-tip.
27 28
Linking objects from another database will create a link to an object in another
database while not copying the table to the current database. The latest object data will
Chapter 07 : Forms and Reports be retrieved every time we access the link.
7.1 Overview
29 30