Dbms Practical
Dbms Practical
Submitted To Submitted By
Mr.Pradeep Sharma Vineet Kumar
Associate Professor Roll No- 2200160140035
Example 1:
Create a client_ vineet table whose structure is:
Example 1: If we want to access the data of all fields of client_vineet table then
we have to write the following syntax:
Select * from client_vineet;
The delete command is used to delete the record in a table. The user can delete a
particular record or all the record in the table by using this command. The delete
command is used in two ways.
1. Delete * from table name;
2. Delete field name from table name;
The first command delete all the record in a particular table immediately after
giving the command on SQL prompt, Where the second command delete only the
record of specified row of the given table.
Deleting a table
Command:DROP TABLE
Syntax:drop table from table name;
This command is use to remove the particular table in the database. It removes
the table in the database immediately after giving this command on the SQL
prompt.
Example 2:
ALTER TABLE client_master
MODIFY(client_fax varchar2(25));
CONSTRAINTS
The value which are enforced on data being entered, and prevent the user from
entering invalid data into table are called constraints. With the help of constraints
are as a part of global table destination by the Oracle engine in its system table.
Example 1:Crete table t1(roll_no number(10) primary key, name var char2(20));
Table level constraints:
If the data constraints defined after defining all the table columns when creating
or altering the table structure it is the table level constraints.
Column level:
Create table t1 (roll_no number (10),UNIQUE);
Table level:
Create table t1(rill_no number(10),name varchar2(20)
UNIQUE(roll_no));
Check constraints:
Check constraints are used to satisfy the condition when you entering the data in
the column .check constraints must be avoided if the constraints can be defined
using not null, primary key or foreign key.
Syntax:
At column level:
Create table t1(roll_no number(10),name varchar2(20)check(name like ‘c
%’),address varchar2(20));
At table level:
Create table (roll_number(10),name varchar2(20),address
varchar2(20)check(name like’c%’));
Syntax:
Create tablet1(roll_no number(10),name varchar2(20),default ‘F’,address
varchar2(20);
DISTINGUISH VALUES
It cannot show you duplicated values. The DISTINCT keyword eliminates rows
from the result of a select command.
Select distinct*from tablename;
Select DISTINCT*from t1;
In column
Select DISTINCTcolumn name from table name;
SYNTAX:
Create table sales_order (order_no number (20),product_no
number (20),Qnt_no number(20) ,Qnt_dispatch number(20),amount
number(10));
HAVING CONDITION
Having condition is applied in the sql query statements only with Group by Clause.
When the user want to see the details of any particular person or product or any
other thing while using Group By Clause, then having condition is applied in the
sql query statement.
EXAMPLE 1: Let the example of sales_order table .The table is given below:
ORDER PRODUCT-NO QTY-ORDERED QTY-DISP
-------------------------------- -------------------------- ------------------
1 1001 10 10
2 1002 10 8
3 1001 10 10
4 1003 5 5
5 1001 5 5
If we want to see only the details corresponding the product no of 1001 then we
can do it by applying the having condition in the query as following.
Select product _no ,sum(qty _ordered)”total qty ordered “ from sales _order
GROUP BY product _no HAVING product _no =(1001)
Example 1:
Retrieve the order numbers, client names and their order dates from the
client_master and sales_order tables. The order date should be displayed in
‘DD//MM//YY’ format and sorted in ascending order.
Here the data required is in two tables sales_order and client_master. These
tables have to be accessed as through as through they were one entity.
Table: Client_master
Client No Name Bal Due
C0006 Ashok Mehra 500
C0002 Vishal Parikh !000
C0001 Ajay Mehta 0
C0005 Rohit Roy 0
Union clause:
Multiple queries can be put together and their output combinedusing the union
clause. The Union clause merge the output of two or more queries into a single
set of rows and columns.
second
Example 1: Retrieve the names of all the clients and salesname in the city of
‘Mumbai’ from the table client_master and salesman_master.
UNION
Select client_no “ID”,name
From client_master
Where city=’Mumbai’;
Then
Select SALESMAN_NO “ID”, NAME
From salesman_master
Where city=’Mumbai’;
Common
Records in
Both queries
Example 1:
Retrieve the salesman name in ‘Mumbai’ whose efforts have resulted into atleast
one sales tranjection.
Salesman_no Name
S00001 Manish Patel
S00003 Nitesh Khanna
Salesman_no Name
The INSERSECT clause picks up records that are comman in both queries.
Thus, the output after applying the INTERSECT clause will be.
OUTPUT:
Salsman_no Name
----------------- ----------------------
S00001 Manish Patel
S00003 Nitesh Khanna
VIEWS
To reduce redundant data to the minimum possible, oracle allows the creation of
an object called a view. A view is map to a select sentence the table on which the
view is based is described in the form clause of select statement. Thus a view is
map to a table will in effect have a subset of the actual column of the table from it
is built. This technical offered a simple effective way of hiding column of a table.
An inserting effect above the view is that it is stored only as the definition in
oracle system catalog.
The Reason:
1. When data security is require.
2. When data redundancy is to be kept to the minimum while maintaining
data security.
Syntax:
UPDATETABLE VIEW:
Create view a2 from roll_no,name,address from tablename;
PL/SQL Block:
PL/SQL permits the creation of structured logical block of code that describes
process which have to applied to data. A single PL/SQL block consists of a set of
sql statement together and pass to the oracle engine. The PL/SQL block contain
the Begin & End section that contain the expression section.
BEGIN:
n:=8 n;
while i<n
loop
r:=&r
area:=pi*power(r,2);
insert into rad values(r,area);
i:i+1;
end loop;
END;
Example 1: The HRD manager decided to raise the salary of all emp in dept no
20 by .05. The record also is being entered in emp raise table. It include emp_no,
date etc. Write the PL / SQL Block for it.
Example 1:Write a PL/SQL code block that will accept an account number from
the user and debit an account number from the user and debit an account of Rs
2000 from the account if the account has a minimum balance of 500 after amount
is debited. The process is to be fired on the account table.
BEGIN:
Acct_no := &acct_no;
SELECT bal INTO acct_balance
FROM accounts
WHERE account_id=acct_no;
Acct_balance := aact_balance_debit_amit;
If acct_balance>=MIN_BAL then
UPDATE ACCOUNT_ id=acct_no;
END IF;
END;
OUTPUT:
Account_id Name Bal
---------------- ----------- ---------
AC001 Anuj 5000
AC002 Robert 10000
AC003 Mita 5000
AC004 Sunita 15000
AC005 Melba 10000