Sie sind auf Seite 1von 6

Experiment: 02

Title: Design & analysis of DBMS using Oracle/Microsoft Access- Data


Insertion, Updating & Deletion

Objectives:
1. To study concept of database & database systems.
2. To create the database in Oracle 10G/ Microsoft Access
3. To enter data in the database in Oracle 10 G/ Microsoft Access
4. To update and delete records using basic SQL commands

Theory:
Database:
A database is collection of interrelated data or information. There is an
interrelation between different fields of database and also there is relation between who
is keeping database and of whom.

Database Management System (DBMS):


A DBMS is a collection of interrelated data and a set of programs to access that
data. Primary goal of DBMS is to provide a way to store & retrieve database information
that is both efficient & convenient.

Relational Database Management System (RDBMS):


RDBMS is most widely used system. It has attained its primary position because
of its simplicity, which eases work of programmers.
RDBMS consists of a collection of tables. Each table has its unique name. Tables
are used to represent the data & relationship among the data. A row in table represents
relationship among a set of values. A row is an entity and table is an entity set. In RDBMS
table is referred as relation & row is referred as tuple. A table has two or more columns.
Column is also known as field and row is a record. Column header is known as attribute
or field name.

Database Language:
Database languages are used to design a database and to store & retrieve
information from database. A query is a statement requesting retrieval of information
from database.

Structured Query Language (SQL):


SQL is most widely used query language. Although SQL is referred as query
language, it can do much more than just query a database. It can define the structure of
data, modify data in the database and specify security constraints.
Database Management System (DBMS):
There are several Database Management Systems (DBMS), such as:
 Microsoft SQL Server
 Oracle
 Sybase
 DBase
 Microsoft Access
 MySQL from Sun Microsystems (Oracle)
 DB2 from IBM etc.

SQL Commands
1. Create Table:
It is the command used to create tables or relations. General form of this command
is as follows

Create table R(A1 D1, A2 D2, -----------, An Dn, <integrity constraint1>,


<integrity constraint2>, --------, <integrity constraintk>);

Where, R is the name of the relation,


Ai is the of the attribute,
Di is the domain of the attribute,
Integrity Constraints:
An authorized user can make changes in the database. Sometimes these changes
may result in loss of data consistency. Integrity constraint ensures that changes made to
database do not result in data inconsistency. Thus integrity constraints guard against
accidental damage to database. Different integrity constraints are available such as
primary key, not null, unique etc.
e.g. consider the query to create student table
Create table student (rollno number, name varchar(10), city varchar(10), class
varchar(10));

2. Insert into:
Insert command is used to insert data or record into a relation. Data/records to be
inserted are specified directly or by writing a query. General form is as follows
Insert into R values (V1, V2, V3, ………….., Vn);
Where R is table name, V1 to Vn are the values of attributes to be inserted.
Sequence of values should be as per the attributes in the table.

e.g. Insert into student values (1134, ‘amit’, ‘miraj’, ‘sytt’)


One record is added in student table.
3. Update:
In certain situations it becomes necessary to change a value in a tuple, without
changing remaining values. For this purpose, update command can be used. Also it is
possible to update some selected tuples from a relation using where clause.
Update R
Set A=V
Where P;
Where R is tha table name which is to be updated, A is attribut whose value is to be
updated and V is the new value of the attribute A, P is predicate or condition. If this
condition is TRUE, then that record is updated; other wise not.

e.g. Update student


Set class= ‘fytt’
Where rollno= 1134
Class of student whose roll number is 1134 is updated.

4. Delete:
Delete command is used to delete whole tuples from a relation. Delete command
can not delete values of particular attributes from a tuple. General form is
Delete from R where P;
Delete whole tuples from relation R if predicate P is true. The where clause can be
omitted in which case all tuples from relation R are deleted. Delete command operates
on only one relation. If tuples from several relations are to be deleted, then for each
relation one delete command should be used.

e.g. Delete from student where rollno = 1234


Record of student whose roll number is 1234 will be deleted.

---------------------------------------------**********--------------------------------------------------------
Experiment: 03
Title: Design & analysis of DBMS using Oracle/Microsoft Access- Data
Retrieval

Objectives:
1. To retrieve data from database
2. To study various clauses, operators, functions

Theory:

SQL Commands
1. SQL Queries:
Query is a statement requesting information from the database. SQL query
consists of 3 clauses: select, from & where. A query takes one or more relations as input
and gives a single relation as output.

Select:
Select clause is used to list the attributes desired in the result of the query.
From:
From clause is used to list the relation from which information is to be retrieved.

Where:
Where clause consists of a predicate/ condition involving attributes of the
relations that appear in from clause. General form of SQL query is

Select A1, A2, --------, An


From R1, R2, -----------, Rm
Where P

Where, Ai is an attribute, Ri is a relation,


P is predicate or condition
If predicate P is true then select attributes A1 to An from relations R1 to Rm.
e.g. Select rollno, name
From student
Where city= ‘Ichalkaranji’;
This query will select roll numbers, names of students who are from Ichalkaranji.

2. Distinct:
The keyword ‘distinct’ is used to eliminate duplicates (repetitions) from the output
of the query.
e.g. Select distinct city
From student
Output of this query will consist of list of cities & city name will not repeat.

3. Asterisk symbol *
To select all attributes from a relation, asterisk symbol, * can be used after select
clause.

e.g. Select * from student


All attributes of student table will be selected.

4. SQL provides logical operators and, or, not which can be used in where clause. Also
SQL provides comparison operators <, <=, >, >=, =, <> which a predicate from where
clause can involve.

5. Like:
The most commonly used operation on strings is pattern matching using operator
like. Patterns are described by using percent (%) operator. This percent (%) character
matches any substring. Patterns are case sensitive & are expressed by like comparison
operator.
e.g. select name from student where class like ‘%tt%’;
This query will select names from student table where class includes substring ‘tt’.

6. Order by:
In actual practice, it may happen that information is not stored in sorted order.
Order by clause can be used to display information in ascending or descending order of
one or more attributes. General form is
Select A1, A2, -------, An
From R
Order by Aa, ----, Ac asc/ desc
After order by clause, specify attributes Aa to Ac on which records are to be sorted.
Specify order after these attributes. Keyword asc is used for ascending order & keyword
desc is used for descending order.

e.g. Select rollno, name


From student
Order by rollno asc
This query will arrange roll numbers & names in ascending order of roll number.

7. Aggregate functions
Aggregate functions are the functions that take a collection of values as input and
return a single value. SQL offers five inbuilt aggregate functions:
1. avg: to compute average
2. sum: to compute total sum
3. min: to find out minimum value
4. max: to find maximum value
5. count: to count number of tuples/ collections

The input to avg and sun functions must be collection of numbers. Other functions
operate on collection of numbers as well as nonnumeric data such as strings.

e.g. Select count(*)


From student
This query will count number of tuples (records), student table has.

8. Group by:
Aggregate functions can be applied not only on a single set of tuples but also to a
group of sets of tuples by using group by clause. The attribute or attributes given in group
by clause are used to form groups. Tuples with the same value on all attributes in the
group by clause are placed in one group.
e.g. consider the query “find the number of students coming from a city”
select count(rollno), city
from student
group by address
Here groups of students from same city are formed & then count function is
applied.

9. Having:
Having clause is used to specify a condition applicable ot a group of records, hence
it will always comes inconjunction with Group by clause. If the condition in having clause
is TRUE, then that group is selected otherwise not.

---------------------------------------------**********--------------------------------------------------------

Das könnte Ihnen auch gefallen