Beruflich Dokumente
Kultur Dokumente
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 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.
SQL Commands
1. Create Table:
It is the command used to create tables or relations. General form of this command
is as follows
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.
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.
---------------------------------------------**********--------------------------------------------------------
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
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.
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.
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.
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.
---------------------------------------------**********--------------------------------------------------------