INDEX
S.No. Particulars Page
No.
1 Introduction to DBMS, Adv, Dis Adv
2 Intro to MsAccess
3 Intro to Oracle
4 SQL – DML, DDL
5 Create a table and Save it using access
6 Create a table and Save using SQL
7 Select records from table SQL
8 Select records from table with a condition
9 Add columns to existing table MsAccess and SQL
10 Update values in a column with SQL
11 Add constraint as primary key in a table MsAccess and
SQL
12 Create two relations R1 and R2 and demonstrate
Relational Algebra and Calculus
13 Display unique records from a table
14 Display all records from a table in ascender order of
department
15 Display students who are either studying BCA or BBA
16 Display all the employees who joined before year 2000
17 Create a form in MsAccess to enter data in a table
18 Create a report in MsAccess to display data in a table
1
1. Introduction to DBMS
Database is a collection of related data and data is a collection of facts and figures
that can be processed to produce information. Mostly data represents recordable
facts. Data aids in producing information, which is based on facts. For example, if
we have data about marks obtained by all students, we can then conclude about
toppers andaverage marks
.
A database management system stores data in such a way that it becomes easier to
retrieve, manipulate,and produce information. DBMS stands for Database
Management System. We can break it like this DBMS = Database + Management
System. Database is a collection of data and Management System is a set of
programs to store and retrieve those data. Based on this we can define DBMS like
this: DBMS is a
collection of inter-related data and set of programs to store & access those data in
an easy and effective manner.
Characteristics :
Traditionally, data was organized in file formats. DBMS was a new concept then, and all the
research was done to make it overcome the deficiencies in traditional style of data management.
A modern DBMS has the following characteristics −
2
Real-world entity − A modern DBMS is more realistic and uses real-world entities to
design its architecture. It uses the behavior and attributes too
Relation-based tables − DBMS allows entities and relations among them to form tables.
0Isolation of data and application − A database system is entirely different than its data.
A database is an active entity, whereas data is said to be passive, on which the database
works and organizes. DBMS also stores metadata, which is data about data, to ease its
own process.
Less redundancy − DBMS follows the rules of normalization, which splits a relation
when any of its attributes is having redundancy in values. Consistency − Consistency is
a state where every relation in a database remains consistent.
Query Language − DBMS is equipped with query language, which makes it more
efficient to retrieve and manipulate data
ACID Properties − DBMS follows the concepts of Atomicity,Consistency, Isolation,
and Durability (normally shortened as ACID).
Multiuser and Concurrent Access − DBMS supports multi-user environment and allows
them to access and manipulate data in parallel.
Multiple views − DBMS offers multiple views for different users. This feature enables
the users to have a concentrate view of the database according to their requirements.
Security − Features like multiple views offer security to some extent where users are
unable to access data of other users and departments. DBMS offers methods to impose
constraints
Users of DBMS :
A typical DBMS has users with different rights and permissions who use it for different purposes.
Some users retrieve data and some back it up. The users of a DBMS can be broadly categorized
as follows −
Administrators − Administrators maintain the DBMS and are responsible for
administrating the database. They are responsible to look after its usage and by whom it
should be used. They create access profiles for users and apply limitations to maintain
isolation and force security. Administrators also look after DBMS resources like system
license, required tools, and other software and hardware related maintenance.
Designers − Designers are the group of people who actually work on the designing part
of the database. They keep a close watch on what data should be kept and in what format.
They identify and design the whole set of entities, relations, constraints, and views.
End Users − End users are those who actually reap the benefits of having a DBMS. End
users can range from simple viewers who pay attention to the logs or market rates to
sophisticated users such as business analysts.
3
Architecture of DBMS :
The design of a DBMS depends on its architecture. It can be centralized or decentralized or
hierarchical. The architecture of a DBMS can be seen as either single tier or multi-tier. An n-tier
architecture divides the whole system into related but independent n modules, which can be
independently modified, altered, changed, or replaced.
In 1-tier architecture, the DBMS is the only entity where the user directly sits on the DBMS and
uses it. Any changes done here will directly be done on the DBMS itself. It does not provide
handy tools for end-users. Database designers and programmers normally prefer to use single-tier
architecture.
If the architecture of DBMS is 2-tier, then it must have an application through which the DBMS
can be accessed. Programmers use 2-tier architecture where they access the DBMS by means of
an application. Here the application tier is entirely independent of the database in terms of
operation, design, and programming.
3-tier Architecture
A 3-tier architecture separates its tiers from each other based on the complexity of the users and
how they use the data present in the database. It is the most widely used architecture to design a
DBMS.
Database (Data) Tier − At this tier, the database resides along with its query processing
languages. We also have the relations that define the data and their constraints at this level.
Application (Middle) Tier − At this tier reside the application server and the programs
that access the database. For a user, this application tier presents an abstracted view of the
database. End-users are unaware of any existence of the database beyond the application.
At the other end, the database tier is not aware of any other user beyond the application
tier. Hence, the application layer sits in the middle and acts as a mediator between the
end-user and the database.
4
User (Presentation) Tier − End-users operate on this tier and they know nothing about
any existence of the database beyond this layer. At this layer, multiple views of the
database can be provided by the application. All views are generated by applications that
reside in the application tier.
Multiple-tier database architecture is highly modifiable, as almost all its components are
independent and can be changed independently.
Applications of DBMS :
Applications where we use Database Management Systems are:
Telecom: There is a database to keeps track of the information regarding calls made,
network usage, customer details etc. Without the database systems it is hard to maintain
that huge amount of data that keeps updating every millisecond.
Industry: Where it is a manufacturing unit, warehouse or distribution centre, each one
needs a database to keep the records of ins and outs. For example distribution centre
should keep a track of the product units that supplied into the centre as well as the
products that got delivered out from the distribution centre on each day; this is where
DBMS comes into picture.
Banking System: For storing customer info, tracking day to day credit and debit
transactions, generating bank statements etc. All this work has been done with the help of
Database management systems.
Education sector: Database systems are frequently used in schools and colleges to store
and retrieve the data regarding student details, staff details, course details, exam details,
payroll data, attendance details, fees details etc. There is a hell lot amount of inter-related
data that needs to be stored and retrieved in an efficient manner.
Online shopping: You must be aware of the online shopping websites such as Amazon,
Flipkart etc. These sites store the product information, your addresses and preferences,
credit details and provide you the relevant list of products based on your query. All this
involves a Database management system.
Drawbacks of File system:
Data Isolation: Because data are scattered in various files, and files may be in different
formats, writing new application programs to retrieve the appropriate data is difficult.
Duplication of data – Redundant data
Dependency on application programs – Changing files would lead to change in
application programs.
5
Advantage of DBMS over file system :
There are several advantages of Database management system over file system. Few of them are
as follows:
No redundant data – Redundancy removed by data normalization
Data Consistency and Integrity – data normalization takes care of it too
Secure – Each user has a different set of access
Privacy – Limited access
Easy access to data
Easy recovery
Flexible
Disadvantages of DBMS over file system :
DBMS implementation cost is high compared to the file system
Complexity: Database systems are complex to understand
Performance: Database systems are generic, making them suitable for various
applications. However this feature affect their performance for some applications
Advantages of DBMS :
Normalization of data possible and therefore duplicate data is removed
Data gets stored at a centeralized place
Data is organised and ordered
Data gets secured
Various types of data analysis can be done
Reports and forms can be created
It becomes easier to update, modify or delete the data
Disadvantages of DBMS :
It is a costly process
Trained people are required to operate database
6
Views of DMBS structure :
Three levels of abstraction:
Physical level: This is the lowest level of data abstraction. It describes how data is actually
stored in database. You can get the complex data structure details at this level.
Logical level: This is the middle level of 3-level data abstraction architecture. It describes what
data is stored in database.
View level: Highest level of data abstraction. This level describes the user interaction with
database system.
Example: Let’s say we are storing customer information in a customer table. At physical level
these records can be described as blocks of storage (bytes, gigabytes, terabytes etc.) in memory.
These details are often hidden from the programmers.
At the logical level these records can be described as fields and attributes along with their data
types, their relationship among each other can be logically implemented. The programmers
generally work at this level because they are aware of such things about database systems.
At view level, user just interact with system with the help of GUI and enter the details at the
screen, they are not aware of how the data is stored and what data is stored; such details are
hidden from them.
7
2. Introduction to MS-Access
Microsoft Access is a type of database software that is used to store information for reporting,
referencing and analysis. With Microsoft Access, you can analyze large amounts of data faster and
more efficiently than with Excel or other types of spreadsheets.
Microsoft Access is a database management system (DBMS) from Microsoft that combines the
relational Microsoft Jet Database Engine with a graphical user interface and software-development
tools. It is a member of the Microsoft Office suite of applications, included in the Professional and
higher editions or sold separately.
Microsoft Access stores data in its own format based on the Access Jet Database Engine. It can
also import or link directly to data stored in other applications and databases.
Software developers, data architects and power users can use Microsoft Access to develop
application software. Like other Microsoft Office applications, Access is supported by Visual
Basic for Applications (VBA), an object-based programming language that can reference a variety
of objects including DAO (Data Access Objects), ActiveX Data Objects, and many other ActiveX
components. Visual objects used in forms and reports expose their methods and properties in the
VBA programming environment, and VBA code modules may declare and call Windows
operating system operations.
What Types of Things Can Microsoft Access do ?
Maintain all information for each client or customer, including addresses, invoices, payment
and order information.
Track financial data without needing a separate software program. If you have the full
Microsoft Office Suite, you may even set payment reminders.
Manage marketing and sales thanks to having all customer information in the database. Send
out flyers, emails and coupons and track how customers respond.
Track production and inventory by entering data on shipments and also knowing when it’s
time to order more of a particular product.
Run reports and analyses using the reports and charts. You can basically run a report on
anything within a matter of minutes, such as customers who are behind on payment.
8
Microsoft Access (MS Access) enables one to manage all important
information from a single database file. Within the file, one can use:
• Tables to store your data.
• Queries to find and retrieve specific data of interest.
• Forms to view, add, and update data in tables.
• Reports to analyze or print data in a specific layout.
• Data access pages to view or update, the data.
CREATING A DATABASE IN MS-ACCESS
To create a database from a template, we first need to open MS Access and
you will see the following screen in which different Access database templates
are displayed.
To view the all the possible databases, you can scroll down or you can also
use the search box.
Let us enter project in the search box and press Enter. You will see the
database templates related to project management.
9
Select the first template. You will see more information related to this
template.
10
After selecting a template related to your requirements, enter a name in
the File name field and you can also specify another location for your file if
you want.
Now, press the Create option. Access will download that database template
and open a new blank database as shown in the following screenshot.
11
Now, click the Navigation pane on the left side and you will see all the other
objects that come with this database.
Click the Projects Navigation and select the Object Type in the menu.
You will now see all the objects types — tables, queries, etc.
12
Create Blank Database
Sometimes database requirements can be so specific that using and
modifying the existing templates requires more work than just creating a
database from scratch. In such case, we make use of blank database.
Step 1 − Let us now start by opening MS Access.
13
Step 2 − Select Blank desktop database. Enter the name and click the Create
button.
Step 3 − Access will create a new blank database and will open up the table
which is also completely blank.
14
3. Introduction to Oracle
Oracle tutorial provides basic and advanced concepts of Oracle. Our Oracle tutorial is designed
for beginners and professionals. Oracle is a relational database management system. It is widely
used in enterprise applications. Our Oracle tutorial includes all topics of Oracle database such as
insert record, update record, delete record, select record, create table, drop table etc.
History of Oracle
Oracle was originally developed by Lawrence Ellison (Larry Ellision) and his two friends and
former co-worker in 1977. Oracle DB runs on the most major platforms like Windows, UNIX,
Linux and Mac OS.
Different editions of Oracle database
Following are the four editions of the Oracle database.
o Enterprise Edition: It is the most robust and secure edition. It offers all features, including
superior performance and security.
o Standard Edition: It provides the base functionality for users that do not require Enterprise
Edition's robust package.
o Express Edition (XE): It is the lightweight, free and limited Windows and Linux edition.
o Oracle Lite: It is designed for mobile devices.
The Oracle Corporation
Oracle Corporation is the largest software company in the field of database business. Its relational
database was the first to support SQL which has since become the industry standard.
Oracle database is one of the most trusted and widely used relational database engines. The biggest
rival of Oracle database is Microsoft's SQL Server.
Oracle CREATE TABLE
In Oracle, CREATE TABLE statement is used to create a new table in the database.
To create a table, you have to name that table and define its columns and datatype for each column.
Syntax:
15
CREATE TABLE table_name(
column1 datatype,
column2 datatype,
column3 datatype,);
Parameters used in syntax
o table_name: It specifies the name of the table which you want to create.
o column1, column2, ... column n: It specifies the columns which you want to add in the
table. Every column must have a datatype. Every column should either be defined as
"NULL" or "NOT NULL". In the case, the value is left blank; it is treated as "NULL" as
default.
Example
CREATE TABLE Persons(
ID int NOTNULL,
LastName varchar(255) NOTNULL,
FirstName varchar(255),
Age int(10),PRIMARYKEY (ID)
);
What is Primary key ?
A primary key is a single field or combination of fields that contains a unique record. It must be
filled. None of the field of primary key can contain a null value. A table can have only one primary
key.
Add Constraint as PRIMARY KEY in Oracle /Sql
CREATE TABLE Persons(
ID int NOTNULL,
LastName varchar(255) NOTNULL,
FirstName varchar(255),
Age int, CONSTRAINT PK_Person PRIMARYKEY (ID,LastName)
);
The SQL SELECT Statement
The SELECT statement is used to select data from a database.
The data returned is stored in a result table, called the result-set.
SELECT Syntax
SELECT column1, column2, ...
FROM table_name;
Here, column1, column2, ... are the field names of the table you want to select data from.
SELECT all the fields available in the table
SELECT * FROM table_name;
Note : ‘ * ’ signifies all colums of a table.
16
4. SQL – DML, DDL
SQL is Structured Query Language, it is a standard language for database management.
Types of SQL Statements
DDL
DDL is short name of Data Definition Language, which deals with database schemas and
descriptions, of how the data should reside in the database.
CREATE – to create database and its objects like (table, index, views, store procedure, function
and triggers)
ALTER – alters the structure of the existing database
DROP – delete objects from the database
TRUNCATE – remove all records from a table, including all spaces allocated for the records are
removed
COMMENT – add comments to the data dictionary
RENAME – rename an object
DML
DML is short name of Data Manipulation Language which deals with data manipulation, and
includes most common SQL statements such SELECT, INSERT, UPDATE, DELETE etc,
and it is used to store, modify, retrieve, delete and update data in database.
SELECT – retrieve data from the a database
INSERT – insert data into a table
17
UPDATE – updates existing data within a table
DELETE – Delete all records from a database table
MERGE – UPSERT operation (insert or update)
CALL – call a PL/SQL or Java subprogram
EXPLAIN PLAN – interpretation of the data access path
LOCK TABLE – concurrency Control
DCL
DCL is short name of Data Control Language which includes commands such as GRANT,
and mostly concerned with rights, permissions and other controls of the database system.
GRANT – allow users access privileges to database
REVOKE – withdraw users access privileges given by using the GRANT command
DDL, Data Definition Language
Create and modify the structure of database object in a database.
These database object may have the Table, view, schema, indexes....etc
e.g.: CREATE, ALTER, DROP, TRUNCATE, COMMIT, etc.
DML, Data Manipulation Language
DML statement are affect on table. So that is the basic operations we perform in a table.
Basic crud operation are perform in table.
These crud operation are perform by the SELECT, INSERT, UPDATE, etc.
Below Commands are used in DML:
INSERT, UPDATE, SELECT, DELETE, etc.
DDL is Data Definition Language : Specification notation for defining the database schema.
It works on Schema level.
DDL commands are:
create,drop,alter,rename,truncate
For example:
create table account ( account-number char(10), balance integer);
DML is Data Manipulation Language .It is used for accessing and manipulating the data.
DML commands are:
select,insert,delete,update,call
For example : select account_number from account;
18
5. CREATING A TABLE IN MS-ACCESS
Let us try and create the first table that will store the basic contact
information concerning the employees as shown in the following table −
Field Name Data Type
EmployeelD AutoNumber
FirstName Short Text
LastName Short Text
Address1 Short Text
Address2 Short Text
City Short Text
State Short Text
Zip Short Text
Phone Short Text
Phone Type Short Text
Let us now have short text as the data type for all these fields and open a
blank database in Access.
19
This is where we left things off. We created the database and then Access automatically
opened up this table-one-datasheet view for a table.
Let us now go to the Field tab and you will see that it is also automatically created. The ID
which is an AutoNumber field acts as our unique identifier and is the primary key for this
table.
20
Click on the Name & Caption option in the Ribbon and you will see the
following dialog box.
Change the name of this field to EmployeeID to make it more specific to
this table. Enter the other optional information if you want and click Ok.
We now have our employee ID field with the caption Employee ID. This is
automatically set to auto number so we don't really need to change the data
type.
Let us now add some more fields by clicking on click to add.
21
Choose Short Text as the field. When you choose short text, Access will then highlight that
field name automatically and all you have to do is type the field name .
Type FirstName as the field name. Similarly, add all the required fields as
shown in the following screenshot.
22
Once all the fields are added, click the Save icon.
You will now see the Save As dialog box, where you can enter a table name for the table.
23
6. Create a table and Save using SQL
24
7. Select records from table SQL
SELECT * FROM Table_name ;
25
8. Select records from table with a condition
The WHERE clause is used to filter records.
The WHERE clause is used to extract only those records that fulfill a specified
Condition.
WHERE Syntax
SELECT column1, column2, ...
FROM table_name
WHERE condition;
Let’s take a table ‘customers’ :
ID Customer City State
Name
1 Rajesh Ludhiana Punjab
2 Abhishek Kolkata West
Bengal
3 Akhand Patiala Punjab
Using condition in sql syntax :
SELECT * FROM customers
WHERE state='punjab';
We get ,
ID Customer City State
Name
1 Rajesh Ludhiana Punjab
3 Akhand Patiala Punjab
9. Add columns to existing table MsAccess and SQL
The ALTER TABLE statement is used to add, delete, or modify columns in an
existing table.
The ALTER TABLE statement is also used to add and drop various constraints on an
existing table.
26
To add a column in a table, use the following syntax:
ALTER TABLE table_name
ADD column_name datatype;
Let’s add column ‘contacts’ in table ‘customers’ :
ID Customer City State
Name
1 Rajesh Ludhiana Punjab
2 Abhishek Kolkata West
Bengal
3 Akhand Patiala Punjab
ALTER TABLE customers
ADD contact number(10);
ID Customer City State Contact
Name
1 Rajesh Ludhiana Punjab
2 Abhishek Kolkata West
Bengal
3 Akhand Patiala Punjab
Adding column/field in MS-Access
Add a field automatically by entering data
You can add a field to a table by typing into the last column in Datasheet view. Access
automatically assigns a data type based on the data that you enter. Access may also
27
automatically set the Format property for a new field. For example, if you enter 10:50
am, Access sets the data type to Date/Time and the Formatproperty to Medium Time.
1. Open the table to which you want to add a field.
2. Type your data in the cell below the Click to Add column header.
Add a field by picking from a list on the Datasheet
You can add a field to the end of a table by picking from a list:
Open the table, and in the last column, click Click to Add.
Add a field in the middle of a table
If you want to add a new field in the middle of table, you can choose a field from
the Fields tab on the ribbon. The Fields tab displays predefined fields that you can add
to a table while working in Datasheet view.
1. Open the table in Datasheet view.
2. Select the field in front of the position where you want to add a new field. For example, if
you want the new field to be the third field in the table, select the second field.
3. On the Fields tab, in the Add & Delete group, click the field type that you want.
10. Update values in a column with SQL
The UPDATE statement is used to modify the existing records in a table.
UPDATE Syntax
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
ID Customer City State
Name
28
1 Rajesh Ludhiana Punjab
2 Abhishek Kolkata West
Bengal
3 Akhand Patiala Punjab
UPDATE Customers
SET CustomerName = 'Sandeep', City= 'Pratpgarh' , State= 'U.P'
WHERE ID = 3;
Thus, we get
ID Customer City State
Name
1 Rajesh Ludhiana Punjab
2 Abhishek Kolkata West
Bengal
3 Sandeep Pratapgarh U.P
11. Add constraint as primary key in a table MS-Access
and SQL
To allow naming of a PRIMARY KEY constraint, and for defining a PRIMARY KEY
constraint on multiple columns, use the following SQL syntax:
MySQL / SQL Server / Oracle / MS Access:
CREATE TABLE Persons (
ID int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Age int,
CONSTRAINT PK_Person PRIMARY KEY (ID,LastName)
);
In the example above there is only ONE PRIMARY KEY (PK_Person). However,
the VALUE of the primary key is made up of TWO COLUMNS (ID + LastName)
29
12. Demonstrate SQL JOINS
30
31
INNER JOIN :
32
LEFT OUTER JOIN :
RIGHT JOIN :
33
FULL OUTER JOIN :
FULL OUTER JOIN WITH WHERE CLAUSE :
34
12. Relational Algebra and Calculus
Relational database systems are expected to be equipped with a query language that can assist its
users to query the database instances. There are two kinds of query languages − relational
algebra and relational calculus.
Relational Algebra
Relational algebra is a procedural query language, which takes instances of relations as input and
yields instances of relations as output. It uses operators to perform queries. An operator can be
either unary or binary. They accept relations as their input and yield relations as their output.
Relational algebra is performed recursively on a relation and intermediate results are also
considered relations.
The fundamental operations of relational algebra are as follows −
Select
Project
Union
Set different
Cartesian product
Rename
Relational Calculus
In contrast to Relational Algebra, Relational Calculus is a non-procedural query language, that is,
it tells what to do but never explains how to do it.
35
13. Display unique records from a table
Shows only unique records from the table
Course table is having duplicate records
SELECT Unique * from COURSE ; Shows only unique rows
36
14. Display all records from a table in ascending order
of rollno
SELECT * from STU ORDER by ROLLNO;
15. Display students who are either studying BCA or
BBA
SELECT * from COURSE where COURSE = ’BCA’ or COURSE = ’BBA’ ;
37
16. Display all the employees who joined AFTER year
2000
SELECT * FROM EMPLOYEES WHERE EMPDOJ > ‘1-JAN-2000’ ;
17. Create a form in MsAccess to enter data in a table
Creating Forms
There are a few methods you can use to create forms in Access. For this, open your Database
and go to the Create tab. In the Forms group, in the upper right-hand corner you will see
the Form Wizard button.
38
click on that button to launch the Form Wizard.
On this first screen in the wizard, you can select fields that you want to display on your form,
and you can choose from fields from more than one table or a query.
Let us assume we want to simply have a quick form that we are going to use for data entry
for our employee information.
From Tables/Queries drop-down list, select tblEmployees table. Click on the double arrow
to move all the fields at once.
Let us just leave it with that one table, and click Next.
39
The following screen in the Form Wizard will ask for the layout that we would like for our
form. We have columnar, tabular, datasheet and justifiedlayouts. We will choose the
columnar layout here and then click Next.
In the following screen, we need to give a title for our form. Let us call it frmEmployees.
Once you have given your form a title, you can open the form to see what that form looks
like, or you can begin entering information into your table. Or you can choose the option to
modify the form's design. Let us choose the first option to open the form to view or enter
information and click Finish.
40
Now, take a look at the following screenshot. This is what your form looks
like. This is a single item form, meaning one record is displayed at a time and
further down you can see the navigation buttons, which is telling us that this
is displaying the record 1 of 9. If you click on that button then, it will move
to the next record.
If you want to jump to the very last record in that form or that table, you can
use the button right beside that right arrow, the arrow with a line after it,
that's the last record button. If you want to add new employee information,
go to the end of this records and then after 9 records you will see a blank
form where you can begin entering out the new employee's information.
41
42
18. Create a report in MsAccess to display data in a
table
We will now take a simple example to understand the process of creating a very simple
report. For this, we need to go to the Create tab.
. Now click on the Report button, which will generate a report based on that query .
43
You will see that the report is open in Layout view. This provides a quick way to adjust the
size or width of any of your fields that you see on the report. Let us now adjust the column
widths to make everything fit in a better way.
Scroll down and adjust the page control at the bottom.
44
This was a very quick way to create a very simple report.
Just like forms, a report is made up of a variety of different sections.
You have the detail section, which is where all of your data lives for the most part.
Let us now change the Title of the report and give it another name.
45
Click on the save icon to save your report.
You will get the above dialog box.
Enter a name for your report and click Ok. If you want to view what this
report will actually look like, in Print Preview, you can go back to the View
button and click on Print Preview to see what this report would look like when
printed either on paper or as a PDF.
46
47
48
49