Professional Documents
Culture Documents
BBA Notes 3rd Yr PDF
BBA Notes 3rd Yr PDF
Computer Applications
System Analysis and Design:
System
A collection of components that work together to realize some objective forms a
system. Basically there are three major components in every system, namely input,
processing and output.
In a system the different components are connected with each other and they are
interdependent. For example, Human body represents a complete natural system.
We are also bound by many national systems such as political system, economic
system, educational system and so forth. The objectives of the system demand that
some output is produced as a result of processing the suitable inputs.
The term “system” originates from the Greek term syst¯ema, which means to
“place together.” Multiple business and engineering domains have definitions of a
system. This text defines a system as:
Characteristics of a System
1
Computer Applications – BBA 3rd year SN
1. Outputs
2. Inputs: The essential elements of Inputs are
a) Accuracy of data
b) Timeliness
c) Proper format
d) Economy.
3. Files
4. Process
Types of Systems
2
Computer Applications – BBA 3rd year SN
someone, referred to as the decision maker, identify a better course of action and
make a better decision than he might have otherwise made.
• System study
• Feasibility study
• System analysis
• System design
• Coding and Implementation
• Testing
• User Implementation
• Maintenance
3
Computer Applications – BBA 3rd year SN
Let us now describe the different phases and the related activities of system
development life cycle in detail.
System study is the first stage of system development life cycle. This gives a
clear picture of what actually the physical system is? In practice, the system
study is done in two phases. In the first phase, the preliminary survey of the
system is done which helps in identifying the scope of the system. The
second phase of the system study is more detailed and in-depth study in
which the identification of user’s requirement and the limitations and
problems of the present system are studied. After completing the system
study, a system proposal is prepared by the System Analyst (who studies the
system) and placed before the user. The proposed system contains the
findings of the present system and recommendations to overcome the
limitations and problems of the present system in the light of the user’s
requirements.
To describe the system study phase more analytically, we would say that
system study phase passes through the following steps:
On the basis of result of the initial study, feasibility study takes place. The
feasibility study is basically the test of the proposed system in the light of its
workability, meeting user’s requirements, effective use of resources and .of
course, the cost effectiveness. The main goal of feasibility study is not to
solve the problem but to achieve the scope. In the process of feasibility
study, the cost and benefits are estimated with greater accuracy.
Based on the user requirements and the detailed analysis of a new system,
the new system must be designed. This is the phase of system designing.
It is a most crucial phase in the development of a system. Normally, the
design proceeds in two stages :
5
Computer Applications – BBA 3rd year SN
There are several tools and techniques used for designing. These tools and
techniques are:
• Flowchart
• Data flow diagram (DFDs)
• Data dictionary
• Structured English
• Decision table
• Decision tree
Each of the above tools for designing will be discussed in detailed in the next
lesson.
It is generally felt that the programs must be modular in nature. This helps in
fast development, maintenance and future change, if required.
(f) Testing
Before actually implementing the new system into operations, a test run of
the system is done removing all the bugs, if any. It is an important phase of a
successful system. After codifying the whole programs of the system, a test
plan should be developed and run on a given set of test data. The output of
the test run should match the expected results.
Using the test data following test run are carried out:
6
Computer Applications – BBA 3rd year SN
• Unit test
• System test
Unit test: When the programs have been coded and compiled and brought to
working conditions, they must be individually tested with the prepared test
data. Any undesirable happening must be noted and debugged (error
corrections).
System Test: After carrying out the unit test for each of the programs of the
system and when errors are removed, then system test is done. At this stage
the test is done on actual data. The complete system is executed on the
actual data. At each stage of the execution, the results or output of the
system is analyzed. During the result analysis, it may be found that the
outputs are not matching the expected out of the system. In such case, the
errors in the particular programs are identified and are fixed and further
tested for the expected output.
When it is ensured that the system is running error-free, the users are called
with their own actual data so that the system could be shown running as per
their requirements.
After having the user acceptance of the new system developed, the
implementation phase begins. Implementation is the stage of a project
during which theory is turned into practice. During this phase, all the
programs of the system are loaded onto the user's computer. After loading
the system, training of the users starts. Main topics of such type of training
are:
After the users are trained about the computerized system, manual working
has to shift from manual to computerized working. The following two
strategies are followed for running the system:
i. Parallel run: In such run for a certain defined period, both the
systems i.e. computerized and manual are executed in parallel. This
strategy is helpful because of the following:
7
Computer Applications – BBA 3rd year SN
i. Pilot run: In this type of run, the new system is installed in parts.
Some part of the new system is installed first and executed
successfully for considerable time period. When the results are found
satisfactory then only other parts are implemented. This strategy
builds the confidence and the errors are traced easily.
(h) Maintenance
Requirements Gathering
8
Computer Applications – BBA 3rd year SN
Requirements engineering
Systematic requirements analysis is also known as requirements engineering. It is
sometimes referred to loosely by names such as requirements gathering,
requirements capture, or requirements specification. The term requirements
analysis can also be applied specifically to the analysis proper, as opposed to
elicitation or documentation of the requirements, for instance.
Cost benefit analysis helps to give management a picture of the costs, benefits and
risks. It usually involves comparing alternate investments.
Cost benefit determines the benefits and savings that are expected from the system
and compares them with the expected costs.
The cost of an information system involves the development cost and maintenance
cost. The development costs are one time investment whereas maintenance costs
are recurring. The development cost is basically the costs incurred during the
various stages of the system development.
Each phase of the life cycle has a cost. Some examples are :
• Personnel
• Equipment
• Supplies
• Overheads
• Consultants' fees
9
Computer Applications – BBA 3rd year SN
In performing Cost benefit analysis (CBA) it is important to identify cost and benefit
factors. Cost and benefits can be categorized into the following categories.
There are several cost factors/elements. These are hardware, personnel, facility,
operating, and supply costs.
In a broad sense the costs can be divided into two types
1. Development costs-
Development costs that are incurred during the development of the system
are one time investment.
• Wages
• Equipment
2. Operating costs,
e.g. , Wages
Supplies
Overheads
3. Hardware/software costs:
4. Personnel costs:
5. Facility costs:
Expenses incurred during the preparation of the physical site where the
system will be operational. These can be wiring, flooring, acoustics, lighting,
and air conditioning.
6. Operating costs:
Operating costs are the expenses required for the day to day running of the
system. This includes the maintenance of the system. That can be in the
10
Computer Applications – BBA 3rd year SN
7. Supply costs:
These are variable costs that vary proportionately with the amount of use of
paper, ribbons, disks, and the like. These should be estimated and included
in the overall cost ofthe system.
Benefits
- Increasing income, or
- Decreasing costs, or
- both
The system will provide some benefits also. Benefits can be tangible or
intangible, direct or indirect. In cost benefit analysis, the first task is to
identify each benefit and assign a monetary value to it.
The two main benefits are improved performance and minimized processing
costs.
Tangible cost and benefits can be measured. Hardware costs, salaries for
professionals, software cost are all tangible costs. They are identified and
measured.. The purchase of hardware or software, personnel training, and
employee salaries are example of tangible costs. Costs whose value cannot
be measured are referred as intangible costs. The cost of breakdown of an
online system during banking hours will cause the bank lose deposits.
11
Computer Applications – BBA 3rd year SN
From the cost accounting point of view, the costs are treated as either direct
or indirect. Direct costs are having rupee value associated with it. Direct
benefits are also attributable to a given project. For example, if the proposed
systems that can handle more transactions say 25% more than the present
system then it is direct benefit.
Indirect costs result from the operations that are not directly associated with
the system. Insurance, maintenance, heat, light, air conditioning are all
indirect costs.
Some costs and benefits are fixed. Fixed costs don't change. Depreciation of
hardware, Insurance, etc are all fixed costs. Variable costs are incurred on
regular basis. Recurring period may be weekly or monthly depending upon
the system. They are proportional to the work volume and continue as long
as system is in operation.
Fixed benefits don't change. Variable benefits are realized on a regular basis.
Example:
12
Computer Applications – BBA 3rd year SN
13
Computer Applications – BBA 3rd year SN
A data file is a single disk file that stores related information on a hard disk
or floppy diskette. For example, a phone book database would be stored in a
single data file.
15
Computer Applications – BBA 3rd year SN
ADVANTAGES OF DBMS
The DBMS (Database Management System) is preferred ever the conventional file
processing system due to the following advantages:
Let us again consider the example of Result system. Suppose that a student having
Roll no -201 changes his course from 'Computer' to 'Arts'. The change is made in
the SUBJECT file but not in RESULT'S file. This may lead to inconsistency of the data.
So we need to centralize the database so that changes once made are reflected to
all the tables where a particulars field is stored. Thus the update is brought
automatically and is known as propagating updates.
3. Better service to the users - A DBMS is often used to provide better services
to the users. In conventional system, availability of information is often poor, since
it normally difficult to obtain information that the existing systems were not
designed for. Once several conventional systems are combined to form one
centralized database, the availability of information and its updateness is likely to
improve since the data can now be shared and DBMS makes it easy to respond to
anticipated information requests.
16
Computer Applications – BBA 3rd year SN
Centralizing the data in the database also means that user can obtain new and
combined information easily that would have been impossible to obtain otherwise.
Also use of DBMS should allow users that don't know programming to interact with
the data more easily, unlike file processing system where the programmer may
need to write new programs to meet every new demand.
For example: - The example of result system that we have already discussed.
Since multiple files are to maintained, as sometimes you may enter a value for
course which may not exist. Suppose course can have values (Computer, Accounts,
Economics, and Arts) but we enter a value 'Hindi' for it, so this may lead to an
inconsistent data, so lack of Integrity.
Even if we centralized the database it may still contain incorrect data. For example:
-
• Salary of full time employ may be entered as Rs. 500 rather than Rs. 5000.
• A student may be shown to have borrowed books but has no enrollment.
• A list of employee numbers for a given department may include a number of non
existent employees.
These problems can be avoided by defining the validation procedures whenever any
update operation is attempted.
6. Standards can be enforced - Since all access to the database must be through
DBMS, so standards are easier to enforce. Standards may relate to the naming of
data, format of data, structure of the data etc. Standardizing stored data formats is
usually desirable for the purpose of data inter¬change or migration between
systems.
the database.
For example: - A DBA must choose best file Structure and access method to give
fast response for the high critical applications as compared to less critical
applications.
10. Data Model must be developed - Perhaps the most important advantage of
setting up of database system is the requirement that an overall data model for an
organization be build. In conventional systems, it is more likely that files will be
designed as per need of particular applications demand. The overall view is often
not considered. Building an overall view of an organization's data is usual cost
effective in the long terms.
12. Concurrent Access of data can be possible while keeping the whole
data of the database consistent.
Disadvantages of DBMS
18
Computer Applications – BBA 3rd year SN
1. COST
2. COMPLEXITY
A data model is a conceptual representation of the data structures that are required by a database.
The data structures include the data objects, the associations between data objects, and the rules
which govern operations on the objects. As the name implies, the data model focuses on what
data is required and how it should be organized rather than what operations will be performed on
the data. To use a common analogy, the data model is equivalent to an architect's building plans.
• It maps well to the relational model. The constructs used in the ER model can
easily be transformed into relational tables.
• it is simple and easy to understand with a minimum of training. Therefore,
the model can be used by the database designer to communicate the design
to the end user.
• In addition, the model can be used as a design plan by the database
developer to implement a data model in specific database management
software.
The ER model views the real world as a construct of entities and association
between entities.
Entities
19
Computer Applications – BBA 3rd year SN
Relationships
Attributes
20
Computer Applications – BBA 3rd year SN
Classifying Relationships
Degree of a Relationship
Binary relationships, the association between two entities are the most
common type in the real world. A recursive binary relationship occurs when
an entity is related to itself. An example might be "some employees are
married to other employees".
A one-to-many (1:N) relationships is when for one instance of entity A, there are
zero, one, or many instances of entity B, but for one instance of entity B, there is
only one instance of entity A. An example of a 1:N relationships is
a department has many employees
each employee is assigned to one department
21
Computer Applications – BBA 3rd year SN
Direction
The direction of a relationship indicates the originating entity of a binary
relationship. The entity from which a relationship originates is the parent entity; the
entity where the relationship terminates is the child entity.
The direction of a relationship is determined by its connectivity. In a one-to-one
relationship the direction is from the independent entity to a dependent entity. If
both entities are independent, the direction is arbitrary. With one-to-many
relationships, the entity occurring once is the parent. The direction of many-to-
many relationships is arbitrary.
Type
An identifying relationship is one in which one of the child entities is also a
dependent entity. A non-identifying relationship is one in which both entities are
independent.
Existence
Existence denotes whether the existence of an entity instance is dependent upon
the existence of another, related, entity instance. The existence of an entity in a
relationship is defined as either mandatory or optional. If an instance of an entity
must always occur for an entity to be included in a relationship, then it is
mandatory. An example of mandatory existence is the statement "every project
must be managed by a single department". If the instance of the entity is not
required, it is optional. An example of optional existence is the statement,
"employees may be assigned to work on projects".
Generalization Hierarchies
ER Notation
• Entities are represented by labeled rectangles. The label is the name of the
entity. Entity names should be singular nouns.
• Relationships are represented by a solid line connecting two entities. The
name of the relationship is written above the line. Relationship names should
be verbs.
• Attributes, when included, are listed inside the entity rectangle. Attributes
which are identifiers are underlined. Attribute names should be singular
nouns.
• Cardinality of many is represented by a line ending in a crow's foot. If the
crow's foot is omitted, the cardinality is one.
• Existence is represented by placing a circle or a perpendicular bar on the line.
Mandatory existence is shown by the bar (looks like a 1) next to the entity for
an instance is required. Optional existence is shown by placing a circle next
to the entity that is optional.
Figure 1: ER Notation
Data models are tools used in analysis to describe the data requirements and assumptions
in the system from a top-down perspective. They also set the stage for the design of
databases later on in the SDLC.
There are three basic elements in ER models:
Entities are the "things" about which we seek information.
Attributes are the data we collect about the entities.
Relationships provide the structure needed to draw information from multiple
entities.
24
Computer Applications – BBA 3rd year SN
Developing an ERD
Consider a hospital:
Patients are treated in a single ward by the doctors assigned to them.
Usually each patient will be assigned a single doctor, but in rare cases they
will have two.
Heathcare assistants also attend to the patients, a number of these are
associated with each ward.
Initially the system will be concerned solely with drug treatment. Each
patient is required to take a variety of drugs a certain number of times per
day and for varying lengths of time.
The system must record details concerning patient treatment and staff
payment. Some staff are paid part time and doctors and care assistants
work varying amounts of overtime at varying rates (subject to grade).
The system will also need to track what treatments are required for which
patients and when and it should be capable of calculating the cost of
treatment per week for each patient (though it is currently unclear to what
use this information will be put).
1. Define Entities: these are usually nouns used in descriptions of the system, in
the discussion of business rules, or in documentation; identified in the narrative
(see highlighted items above).
25
Computer Applications – BBA 3rd year SN
3. Add attributes to the relations; these are determined by the queries,and may
also suggest new entities, e.g. grade; or they may suggest the need for
keys or identifiers.
What questions can we ask?
a. Which doctors work in which wards?
b. How much will be spent in a ward in a given week?
c. How much will a patient cost to treat?
d. How much does a doctor cost per week?
e. Which assistants can a patient expect to see?
f. Which drugs are being used?
4. Add cardinality to the relations
Many-to-Many must be resolved to two one-to-manys with an additional
entity
Usually automatically happens
Sometimes involves introduction of a link entity (which will be all foreign
key) Examples: Patient-Drug
5. This flexibility allows us to consider a variety of questions such as:
a. Which beds are free?
b. Which assistants work for Dr. X?
c. What is the least expensive prescription?
d. How many doctors are there in the hospital?
e. Which patients are family related?
6. Represent that information with symbols. Generally E-R Diagrams require the
use of the following symbols:
Reading an ERD
26
Computer Applications – BBA 3rd year SN
It takes some practice reading an ERD, but they can be used with clients to
discuss business rules.
These allow us to represent the information from above such as the E-R Diagram
below:
Now, think about a university in terms of an ERD. What entities, relationships and
attributes might you consider? Look at this simplified view. There is also an
example of a simplified view of an airline on that page.
Database Normalization
In the field of relational database design, normalization is a systematic way of
ensuring that a database structure is suitable for general-purpose querying and free
of certain undesirable characteristics—insertion, update, and deletion
27
Computer Applications – BBA 3rd year SN
An update anomaly. Employee 519 is shown as having different addresses on different records.
28
Computer Applications – BBA 3rd year SN
An insertion anomaly. Until the new faculty member, Dr. Newsome, is assigned to teach at
least one course, his details cannot be recorded.
A deletion anomaly. All information about Dr. Giddens is lost when he temporarily ceases to be
assigned to any courses.
Normalization
First Normal Form
Do not use multiple fields in a single table to store similar data. For example,
to track an inventory item that may come from two possible sources, an
inventory record may contain fields for Vendor Code 1 and Vendor Code 2.
But what happens when you add a third vendor? Adding a field is not the
answer; it requires program and table modifications and does not smoothly
accommodate a dynamic number of vendors. Instead, place all vendor
information in a separate table called Vendors, then link inventory to vendors
with an item number key, or vendors to inventory with a vendor code key.
For a table to be in first normal form, data must be broken up into the smallest
units possible. For example, the following table is not in first normal form.
29
Computer Applications – BBA 3rd year SN
To conform to first normal form, this table would require additional fields.
The name field should be divided into first and last name and the address should
be divided by street, city state, and zip like this.
The problem here is that each representative can have multiple clients not
all will have three. Some may have less as is the case in the second record,
tying up storage space in your database that is not being used, and some may
have more, in which case there are not enough fields. The solution to this is
to add a record for each new piece of information.
Notice the splitting of the first and last name fields again.
30
Computer Applications – BBA 3rd year SN
This table is now in first normal form. Note that by avoiding repeating groups
of fields, we have created a new problem in that there are identical values
in the primary key field, violating the rules of the primary key. In order to
remedy this, we need to have some other way of identifying each record. This
can be done with the creation of a new key called client ID.
This new field can now be used in conjunction with the Rep ID field to create
a multiple field primary key. This will prevent confusion if ever more than
one Representative were to serve a single client.
• Create separate tables for sets of values that apply to multiple records.
• Relate these tables with a foreign key.
A table is said to be in 2NF if it is in 1NF and all non key attributes are fully
functionally dependent on the primary key.
A fully functional dependency is a dependency where the r.h.s (dependent) is fully
dependent on the composite L.h.s (determinant) part. i.e AB --- > C. Then C is fully
functionally dependent on AB. If A --- > C or B --- > C holds then it is not to
be said as fully functionally dependency rather partial dependency.
Records should not depend on anything other than a table's primary key (a
compound key, if necessary). For example, consider a customer's address in an
accounting system. The address is needed by the Customers table, but also by the
Orders, Shipping, Invoices, Accounts Receivable, and Collections tables. Instead of
storing the customer's address as a separate entry in each of these tables, store it
in one place, either in the Customers table or in a separate Addresses table.
31
Computer Applications – BBA 3rd year SN
The second normal form applies only to tables with multiple field primary
keys. Take the following table for example.
The second normal form states that each field in a multiple field primary key
table must be directly related to the entire primary key. Or in other words,
each non-key field should be a fact about all the fields in the primary key.
Only fields that are absolutely necessary should show up in our table, all other
fields should reside in different tables. In order to find out which
fields are necessary we should ask a few questions of our database. In our
preceding example, I should ask the question "What information is this
table meant to store?" Currently, the answer is not obvious. It may be
meant to store information about individual clients, or it could be
holding data for employees time cards. As a further example, if my
database is going to contain records of employees I may want a table of
demographics and a table for payroll. The demographics will have all the
employees personal information and will assign them an ID number. I should
not have to enter the data twice, the payroll table on the other hand should
refer to each employee only by their ID number. I can then link the two tables
by a relationship and will then have access to all the necessary
data.
In the table of the preceding example we are devoting three field to the
identification of the employee and two to the identification of the
client. I could identify them with only one field each -- the primary
key. I can then take out the extraneous fields and put them in their own
table. For example, my database would then look like the following.
32
Computer Applications – BBA 3rd year SN
Rep
First Name Last Name
ID*
TS-89 Gilroy Gladstone
RK-56 Mary Mayhem
Client
Client Name
ID*
978 US Corp
665 Taggarts
782 Kilroy Inc.
221 Italiana
982 Linkers
These tables are now in normal form. By splitting off the unnecessary
information and putting it in its own tables, we have eliminated redundancy and
put our first table in second normal form. These tables are now ready to
be linked through relationship to each other.
33
Computer Applications – BBA 3rd year SN
I.e. in 3rd normal form there should not be any transitive dependency.
A table is said to be in 3NF if it is in 2NF and every non key attributes are
not transitively dependent on the Primary key. I.e. there should not be
any transitive dependency.
ClerkNo, ClerkName
All of these fields except the primary key will be removed from the original table.
The primary key will be left in the original table to allow linking of data as follows:
Together with the unchanged tables below, these tables make up the database in
third normal form.
ItemNo, Description
34
Computer Applications – BBA 3rd year SN
Values in a record that are not part of that record's key do not belong in the
table. In general, any time the contents of a group of fields may apply to
more than a single record in the table, consider placing those fields in a
separate table.
It may be more feasible to apply third normal form only to data that changes
frequently. If some dependent fields remain, design your application to
require the user to verify all related fields when any one is changed.
SQL
SQL often referred to as Structured Query Language is a database computer
language designed for managing data in relational database management systems
(RDBMS), and originally based upon relational algebra. Its scope includes data
query and update, schema creation and modification, and data access control. SQL
was one of the first languages for Edgar F. Codd's relational model in his influential
1970 paper, "A Relational Model of Data for Large Shared Data Banks"[4] and
became the most widely used language for relational databases.
35
Computer Applications – BBA 3rd year SN
SQL was developed at IBM by Donald D. Chamberlin and Raymond F. Boyce in the
early 1970s. This version, initially called SEQUEL, was designed to manipulate and
retrieve data stored in IBM's original relational database product, System R.
Queries
The most common operation in SQL is the query, which is performed with the declarative
SELECT statement. SELECT retrieves data from one or more tables, or expressions. Standard
SELECT statements have no persistent effects on the database. Some non-standard
implementations of SELECT can have persistent effects, such as the SELECT INTO syntax that
exists in some databases.[10]
Queries allow the user to describe desired data, leaving the database management system
(DBMS) responsible for planning, optimizing, and performing the physical operations necessary
to produce that result as it chooses.
A query includes a list of columns to be included in the final result immediately following the
SELECT keyword. An asterisk ("*") can also be used to specify that the query should return all
columns of the queried tables. SELECT is the most complex statement in SQL, with optional
keywords and clauses that include:
• The FROM clause which indicates the table(s) from which data is to be retrieved. The FROM
clause can include optional JOIN subclauses to specify the rules for joining tables.
• The WHERE clause includes a comparison predicate, which restricts the rows returned by
the query. The WHERE clause eliminates all rows from the result set for which the
comparison predicate does not evaluate to True.
• The GROUP BY clause is used to project rows having common values into a smaller set of
rows. GROUP BY is often used in conjunction with SQL aggregation functions or to
eliminate duplicate rows from a result set. The WHERE clause is applied before the GROUP
BY clause.
36
Computer Applications – BBA 3rd year SN
• The HAVING clause includes a predicate used to filter rows resulting from the GROUP BY
clause. Because it acts on the results of the GROUP BY clause, aggregation functions can
be used in the HAVING clause predicate.
• The ORDER BY clause identifies which columns are used to sort the resulting data, and in
which direction they should be sorted (options are ascending or descending). Without an
ORDER BY clause, the order of rows returned by an SQL query is undefined.
The following is an example of a SELECT query that returns a list of expensive books. The query
retrieves all rows from the Book table in which the price column contains a value greater than
100.00. The result is sorted in ascending order by title. The asterisk (*) in the select list indicates
that all columns of the Book table should be included in the result set.
SELECT *
FROM Book
WHERE price > 100.00
ORDER BY title;
Data manipulation
The Data Manipulation Language (DML) is the subset of SQL used to add, update
and delete data:
UPDATE My_table
SET field1 = 'updated value'
WHERE field2 = 'N';
• TRUNCATE deletes all data from a table in a very fast way. It usually implies a
subsequent COMMIT operation.
• MERGE is used to combine the data of multiple tables. It combines the
INSERT and UPDATE elements. It is defined in the SQL:2003 standard; prior to
that, some databases provided similar functionality via different syntax,
sometimes called "upsert".
Transaction controls(TCL)
37
Computer Applications – BBA 3rd year SN
Once the COMMIT statement completes, the transaction's changes cannot be rolled
back.
COMMIT and ROLLBACK terminate the current transaction and release data locks. In
the absence of a START TRANSACTION or similar statement, the semantics of SQL
are implementation-dependent. Example: A classic bank transfer of funds
transaction.
START TRANSACTION;
UPDATE Account SET amount=amount-200 WHERE account_number=1234;
UPDATE Account SET amount=amount+200 WHERE account_number=2345;
IF ERRORS=0 COMMIT;
IF ERRORS<>0 ROLLBACK;
Data definition
The Data Definition Language (DDL) manages table and index structure. The most
basic items of DDL are the CREATE, ALTER, RENAME, DROP and TRUNCATE
statements:
38
Computer Applications – BBA 3rd year SN
Example:
Embedded SQL
Embedded SQL is a method of combining the computing power of a programming
language and the database manipulation capabilities of SQL. Embedded SQL
statements are SQL statements written in line with the program source code of the
host language. The embedded SQL statements are parsed by an embedded SQL
preprocessor and replaced by host-language calls to a code library. The output from
the preprocessor is then compiled by the host compiler. This allows programmers to
embed SQL statements in programs written in any number of languages such as:
C/C++, COBOL and FORTRAN.
The ANSI SQL standards committee defined the embedded SQL standard in two
steps: a formalism called Module Language was defined, then the embedded SQL
standard was derived from Module Language.[1] The SQL standard defines
embedding of SQL as embedded SQL and the language in which SQL queries are
embedded is referred to as the host language. A popular host language is C. The
mixed C and embedded SQL is called Pro*C in Oracle and Sybase database
management systems. In the PostgreSQL database management system this
precompiled version is called ECPG. Other embedded SQL precompilers are
Pro*Ada, Pro*COBOL, Pro*FORTRAN, Pro*Pascal, and Pro*PL/I.
Oracle Corporation
Ada
Pro*Ada was officially desupported by Oracle in version 7.3. Starting with Oracle8,
Pro*Ada has been replaced by SQL*Module but appears to have not been updated
39
Computer Applications – BBA 3rd year SN
C/C++
COBOL
Fortran
Pascal
PL/I
Pro*PL/I was not released with Oracle8. The Pro*PL/I Supplement to the Oracle
Precompilers Guide, however, continues to make appearances in the Oracle
Documentation Library (current as of release 11g).[4]
PostgreSQL
C/C++
COBOL
Altibase
C/C++
SESC is an embedded SQL precompiler provided by Altibase Corp. for its DBMS
server.
40
Computer Applications – BBA 3rd year SN
With DataFlex 3.2 and Visual DataFlex you can pass SQL statements via one of the
Data Access CLI connectivity kits to Microsoft SQL Server, IBM DB2 or any ODBC
supporting database. The results can be retrieved and processed.
MySQL
COBOL
File Organization
Introduction
File organization is the methodology which is applied to structured computer files. Files contain
computer records which can be documents or information which is stored in a certain way for
later retrieval. File organization refers primarily to the logical arrangement of data (which can
itself be organized in a system of records with correlation between the fields/columns) in a file
system. It should not be confused with the physical storage of the file in some types of storage
media. There are certain basic types of computer file, which can include files stored as blocks of
data and streams of data, where the information streams out of the file while it is being read until
the end of the file is encountered.
We will examine various ways that files can be stored and organized. Files are presented to the
application as a stream of bytes and then an EOF (end of file) condition.
A program that uses a file needs to know the structure of the file and needs to interpret its
contents.
41
Computer Applications – BBA 3rd year SN
It is a high-level design decision to specify a system of file organization for a computer software
program or a computer system designed for a particular purpose. Performance is high on the list
of priorities for this design process, depending on how the file is being used. The design of the
file organization usually depends mainly on the system environment. For instance, factors such
as whether the file is going to be used for transaction-oriented processes like OLTP or Data
Warehousing, or whether the file is shared among various processes like those found in a typical
distributed system or standalone. It must also be asked whether the file is on a network and used
by a number of users and whether it may be accessed internally or remotely and how often it is
accessed.
However, all things considered the most important considerations might be:
A file should be organized in such a way that the records are always available for processing
with no delay. This should be done in line with the activity and volatility of the information.
1. Heap (unordered)
2. Sorted
1. Sequential (SAM)
2. Line Sequential (LSAM)
3. Indexed Sequential (ISAM)
3. Hashed or Direct
Sequential Organization
42
Computer Applications – BBA 3rd year SN
A sequential file contains records organized in the order they were entered. The
order of the records is fixed. The records are stored and sorted in physical,
contiguous blocks within each block the records are in sequence.
Records in these files can only be read or written sequentially.
Once stored in the file, the record cannot be made shorter, or longer, or deleted.
However, the record can be updated if the length does not change. (This is done by
replacing the records by creating a new file.) New records will always appear at the
end of the file.
If the order of the records in a file is not important, sequential organization
will suffice, no matter how many records you may have. Sequential output is also
useful for report printing or sequential reads which some programs prefer to do.
Line-Sequential Organization
Line-sequential files are like sequential files, except that the records can contain
only characters as data. Line-sequential files are maintained by the native byte
stream files of the operating system.
In the COBOL environment, line-sequential files that are created with WRITE
statements with the ADVANCING phrase can be directed to a printer as well as to a
disk.
Indexed-Sequential Organization
Key searches are improved by this system too. The single-level indexing structure is
the simplest one where a file, whose records are pairs, contains a key pointer. This
pointer is the position in the data file of the record with the given key. A subset of
the records, which are evenly spaced along the data file, is indexed, in order to
mark intervals of data records.
This is how a key search is performed: the search key is compared with the index
keys to find the highest index key coming in front of the search key, while a linear
search is performed from the record that the index key points to, until the search
key is matched or until the record pointed to by the next index entry is reached.
Regardless of double file access (index + data) required by this sort of search, the
access time reduction is significant compared with sequential file searches.
Let's examine, for sake of example, a simple linear search on a 1,000 record
sequentially organized file. An average of 500 key comparisons is needed (and
this assumes the search keys are uniformly distributed among the data keys).
However, using an index evenly spaced with 100 entries, the total number of
comparisons is reduced to 50 in the index file plus 50 in the data file: a five to one
reduction in the operations count!
Hierarchical extension of this scheme is possible since an index is a sequential file
in itself, capable of indexing in turn by another second-level index, and so forth and
so on. And the exploit of the hierarchical decomposition of the searches more and
more, to decrease the access time will pay increasing dividends in the reduction of
processing time. There is however a point when this advantage starts to be reduced
by the increased cost of storage and this in turn will increase the index access time.
location of each record. Records can be accessed sequentially or directly, via the
index. The index is stored in a file and read into memory at the point when the file
is opened. Also, indexes must be maintained.
Life sequential organization the data is stored in physical contiguous box. However
the difference is in the use of indexes. There are three areas in the disc storage:
Inverted List
In file organization, this is a file that is indexed on many of the attributes of the data
itself. The inverted list method has a single index for each key type. The records are
not necessarily stored in a sequence. They are placed in the data storage area, but
indexes are updated for the record keys and location.
Here's an example, in a company file, an index could be maintained for all products,
and another one might be maintained for product types. Thus, it is faster to search
the indexes than every record. These types of file are also known as "inverted
indexes." Nevertheless, inverted list files use more media space and the storage
devices get full quickly with this type of organization. The benefits are apparent
immediately because searching is fast. However, updating is much slower.
Content-based queries in text retrieval systems use inverted indexes as their
preferred mechanism. Data items in these systems are usually stored compressed
which would normally slow the retrieval process, but the compression algorithm will
be chosen to support this technique.
When querying a file there are certain circumstances when the query is designed to
be modal which means that rules are set which require that different information
be held in the index. Here's an example of this modality: when phrase querying is
undertaken, the particular algorithm requires that offsets to word classifications are
held in addition to document numbers.
44
Computer Applications – BBA 3rd year SN
A distributed database is a database that is under the control of a central database management
system (DBMS) in which storage devices are not all attached to a common CPU. It may be
stored in multiple computers located in the same physical location, or may be dispersed over a
network of interconnected computers.
Collections of data (e.g. in a database) can be distributed across multiple physical locations. A
distributed database can reside on network servers on the Internet, on corporate intranets or
extranets, or on other company networks. Replication and distribution of databases improve
database performance at end-user worksites. Template: Needs clarification
To ensure that the distributive databases are up to date and current, there are two processes:
replication and duplication. Replication involves using specialized software that looks for
changes in the distributive database. Once the changes have been identified, the replication
process makes all the databases look the same. The replication process can be very complex and
time consuming depending on the size and number of the distributive databases. This process can
also require a lot of time and computer resources. Duplication on the other hand is not as
complicated. It basically identifies one database as a master and then duplicates that database.
The duplication process is normally done at a set time after hours. This is to ensure that each
distributed location has the same data. In the duplication process, changes to the master database
only are allowed. This is to ensure that local data will not be overwritten. Both of the processes
can keep the data current in all distributive locations.
Besides distributed database replication and fragmentation, there are many other distributed
database design technologies. For example, local autonomy, synchronous and asynchronous
distributed database technologies. These technologies' implementation can and does depend on
the needs of the business and the sensitivity/confidentiality of the data to be stored in the
database, and hence the price the business is willing to spend on ensuring data security,
consistency and integrity.
Important considerations
45
Computer Applications – BBA 3rd year SN
Single site failure does not affect performance of system. All transactions follow A.C.I.D.
property: a-atomicity, the transaction takes place as whole or not at all; c-consistency, maps one
consistent DB state to another; i-isolation, each transaction sees a consistent DB; d-durability,
the results of a transaction must survive system failures. The Merge Replication Method used to
consolidate the data between databases.
• Complexity — extra work must be done by the DBAs to ensure that the
distributed nature of the system is transparent. Extra work must also be done
to maintain multiple disparate systems, instead of one big one. Extra
database design work must also be done to account for the disconnected
nature of the database — for example, joins become prohibitively expensive
when performed across multiple systems.
• Economics — increased complexity and a more extensive infrastructure
means extra labour costs.
• Security — remote database fragments must be secured, and they are not
centralized so the remote sites must be secured as well. The infrastructure
46
Computer Applications – BBA 3rd year SN
must also be secured (e.g., by encrypting the network links between remote
sites).
• Difficult to maintain integrity — in a distributed database, enforcing integrity
over a network may require too much of the network's resources to be
feasible.
• Inexperience — distributed databases are difficult to work with, and as a
young field there is not much readily available experience on proper practice.
• Lack of standards – there are no tools or methodologies yet to help users
convert a centralized DBMS into a distributed DBMS.
• Database design more complex – besides of the normal difficulties, the
design of a distributed database has to consider fragmentation of data,
allocation of fragments to specific sites and data replication.
• Additional software is required.
• Operating System should support distributed environment.
• Concurrency control: it is a major issue. It is solved by locking and time
stamping.
Consider the motor car. If a car were designed as a single machine, it would be seen
as hugely complex with lots of opportunities for failure. However, when broken
down into its constituent parts, such as wheels, pedals, doors, etc. the individual
design items become simpler. Each part (or object) is created independently, tested
carefully and then assembled into the final product. The creation of the parts can be
simplified further when they are broken down into even simpler items. For example,
when each door is considered as being composed of an outer panel, handle, inner
panel and window.
47
Computer Applications – BBA 3rd year SN
The car example is analogous to the object-oriented software. Rather than writing a
huge program to create, for example, a project management system, the solution is
broken into real-world parts such as project, task, estimate, actual, deliverable, etc.
Each of these can then be developed and tested independently before being
combined.
An object-oriented program may be considered a collection of interacting
objects. Each object is capable of sending and receiving messages, and processing
data. Consider the objects of a driver, a car, and a traffic light. When the traffic
light changes, it sends a virtual message to the driver. The driver receives the
message, and then chooses to accelerate or decelerate. This sends a virtual
message to the car. When the car's speed changes, it sends a virtual message back
to the driver, via the speedometer.
Key Concepts
The basic building blocks of object-oriented programming are the class and the
object. A class defines the available characteristics and behavior of a set of similar
objects and is defined by a programmer in code. A class is an abstract definition
that is made concrete at run-time when objects based upon the class are
instantiated and take on the class' behavior.
As an analogy, let's consider the concept of a 'vehicle' class. The class developed by
a programmer would include methods such as Steer(), Accelerate() and Brake(). The
class would also include properties such as Colour, NumberOfDoors, TopSpeed and
NumberOfWheels. The class is an abstract design that becomes real when objects
such as Car, RacingCar, Tank and Tricycle are created, each with its own version of
the class' methods and properties.
Class
A class defines the characteristics of an object i.e its an template for creating
objects. Characteristics include: Attributes (fields or properties), and behaviors
(methods or operations). For example, a "Car" class could have properties such as:
year, make, model, color, number of doors, and engine. Behaviors of the "Car"
class include: On, off, change gears, accelerate, decelerate, turn, and brake.
Object
Method
48
Computer Applications – BBA 3rd year SN
Message Passing
• Message passing (or method calling) is the process where an object sends
data to another object to invoke a method. For example, when the object
called "joe" (an instance of the driver class), presses the gas pedal, he
literally passes an accelerate message to object "my Porsche", which in turn,
invokes the "my Porsche" accelerate method.
Encapsulation
Encapsulation conceals the functional details of a class from objects that send
messages to it. For example, the "Porsche Carrera GT" class has a method called
"accelerate". The code for the "accelerate" method defines exactly how
acceleration occurs. In this example, fuel is pumped from gas tank and mixed with
air in the cylinders. Pistons move causing compression, resulting in combustion,
etc. Object "Joe" is an instance of the "Driver" class. It does not need to know how
"my Porsche" accelerates when sending it an accelerate message.
49
Computer Applications – BBA 3rd year SN
Abstraction
Abstraction is the practice of reducing details so that someone can focus on a few
consepts at a time. For example, "my Porsche" may be treated as a "Car" most of
the time. It may sometimes be treated as a "Porsche Carrera GT" to access specific
properties and methods relevant to "Porsche Carrera GT". It could also be treated
as a vehichle, the parent class of "Car" when considering all traffic in your
neighborhood.
Inheritance
• We could create a subclass of "Porsche car" called "Porsche Carrera GT". The
"Porsche Carrerra GT" class could further specify a default model of "Carrera
GT" and "number of doors" as two. It could also include a new method called
"deploy rear wing spoiler".
• The object of "my Porsche" may be instantiated from class "Porsche Carrera
GT" instead of class "Car". This allows sending a message to invoke the new
method "deploy rear wing spoiler".
50
Computer Applications – BBA 3rd year SN
Polymorphism
Function Overloading
We are overloading a function name f by declaring more than one function with the name f in
the same scope. The declarations of f must differ from each other by the types and/or the number
of arguments in the argument list. When you call an overloaded function named f, the correct
function is selected by comparing the argument list of the function call with the parameter list of
each of the overloaded candidate functions with the name f. A candidate function is a function
that can be called based on the context of the call of the overloaded function name.
Consider a function print, which displays an int. As shown in the following example, you can
overload the function print to display other types, for example, double and char*. You can
have three functions with the same name, each performing a similar operation on a different data
type:
#include <iostream>
using namespace std;
void print(int i) {
cout << " Here is int " << i << endl;
}
void print(double f) {
cout << " Here is float " << f << endl;
}
void print(char* c) {
cout << " Here is char* " << c << endl;
}
51
Computer Applications – BBA 3rd year SN
int main() {
print(10);
print(10.10);
print("ten");
}
Here is int 10
Here is float 10.1
Here is char* ten
Virtual Function
C++ virtual function is a member function of a class, whose functionality can be
over-ridden in its derived classes. The whole function body can be replaced with a
new set of implementation in the derived class. The concept of c++ virtual
functions is different from C++ Function overloading.
The difference between a non-virtual c++ member function and a virtual member
function is, the non-virtual member functions are resolved at compile time. This
mechanism is called static binding. Whereas the c++ virtual member functions
are resolved during run-time. This mechanism is known as dynamic binding.
}
};
class CommandButton : public Window
{
public:
void Create()
{
cout<<"Derived class Command Button - Overridden C++ virtual
function"<
}
};
void main()
{
Window *x, *y;
x = new Window();
x->Create();
y = new CommandButton();
y->Create();
}
Friend Functions
In this C++ tutorial, you will learn about friend functions, need for friend function,
how to define and use friend function and few important points regarding friend
function, explained with example.
53
Computer Applications – BBA 3rd year SN
As we know from access specifies, when a data is declared as private inside a class,
and then it is not accessible from outside the class. A function that is not a member
or an external class will not be able to access the private data. A programmer may
have a situation where he or she would need to access private data from non-
member functions and external classes. For handling such cases, the concept of
Friend functions is a useful tool.
A friend function is used for accessing the non-public members of a class. A class
can allow non-member functions and other classes to access its own private data,
by making them friends. Thus, a friend function is an ordinary function or a member
of another class.
The friend function is written as any other normal function, except the function
declaration of these functions is preceded with the keyword friend. The friend
function must have the class to which it is declared as friend passed to it in
argument.
• The keyword friend is placed only in the function declaration of the friend
function and not in the function definition.
.
• It is possible to declare a function as friend in any number of classes.
.
• When a class is declared as a friend, the friend class has access to the private
data of the class that made this a friend.
.
• A friend function, even though it is not a member function, would have the
rights to access the private members of the class.
.
• It is possible to declare the friend function as either private or public.
.
• The function can be invoked without the use of an object. The friend function
has its argument as objects, seen in example below.
#include
class exforsys
{
private:
54
Computer Applications – BBA 3rd year SN
int a,b;
public:
void test()
{
a=100;
b=200;
}
friend int compute(exforsys e1)
//Friend Function Declaration with keyword friend and with the object of
class exforsys to which it is friend passed to it
};
main()
{
exforsys e;
e.test();
cout<<"The result is:"<
//Calling of Friend Function with object as argument.
}
Composition
Objects can work together in many ways within a system. In some situations, classes and objects
can be tightly coupled together to provide more complex functionality. This is known as
composition. In the car example, the wheels, panels, engine, gearbox, etc. can be thought of as
individual classes. To create the car class, you link all of these objects together, possibly adding
55
Computer Applications – BBA 3rd year SN
further functionality. The internal workings of each class are not important due to encapsulation
as the communication between the objects is still via passing messages to their public interfaces.
Modularity
In addition to the concepts described above, object-oriented programming also permits increased
modularity. Individual classes or groups of linked classes can be thought of as a module of code
that can be re-used in many software projects. This reduces the need to redevelop similar
functionality and therefore can lower development time and costs.
56