Details About DDM Lab
Details About DDM Lab
Details About DDM Lab
3
Practicing DML Commands
4 Normalization
5 Procedures
DATE:
AIM: Analyze the problem and come with the entities in it. Identify what
Data has to be persisted in the databases.
The attributes in
the Entities:
Bus:( Entity)
Reservation (Entity)
Ticket :(Entity)
Passenger:
Cancellation (Entity)
Concept design with E-R Model:
RESULT:
Thus the program to design a database using ER diagram has been done
successfully.
Exp.No: 02
Name Type
Empno Number
Ename Varchar2(10)
Job Varchar2(10)
Mgr Number
Sal Number
SOLUTION:
SQL> create table employee(empnonumber,ename varchar2(10),job
varchar2(10),mgrnumber,sal number);
Table created.
SQL> desc employee;
Name Null? Type
EMPNO
NUMBER
ENAME VARCHAR2(10)
JOB VARCHAR2(10)
MGR NUMBER
SAL NUMBER
EMPNO NUMBER
ENAME VARCHAR2(10)
JOB VARCHAR2(10)
MGR NUMBER
SAL NUMBER
COMMISSION NUMBER
Enter value for mgr: 1234 Enter value for sal: 10000 Enter value for commission:70
old 1: insert into employee values(&empno,'&ename','&job',&mgr,&sal,'&commission') new 1:
insert into employee values(101,'abhi','manager',1234,10000,'70')
1 row created.
SQL> /
Enter value for empno: 102 Enter value for ename: rohith Enter value for job: analyst Enter
value for mgr: 2345 Enter value for sal: 9000
Enter value for commission: 65
old 1: insert into employee values(&empno,'&ename','&job',&mgr,&sal,'&commission') new 1:
insert into employee values(102,'rohith','analyst',2345,9000,'65')
1 row created.
SQL> /Enter value for empno: 103 Enter value for ename: david Enter value for job: analyst
Enter value for mgr: 3456 Enter value for sal: 9000
Enter value for commission: 65
old 1: insert into employee values(&empno,'&ename','&job',&mgr,&sal,'&commission') new 1:
insert into employee values(103,'david','analyst',3456,9000,'65')
1 row created.
SQL> /Enter value for empno: 104 Enter value for ename: rahul Enter value for job: clerk
Enter value for mgr: 4567 Enter value for sal: 7000
Enter value for commission: 55
old 1: insert into employee values(&empno,'&ename','&job',&mgr,&sal,'&commission') new 1:
insert into employee values(104,'rahul','clerk',4567,7000,'55')
1 row created.
SQL> / Enter value for empno: 105 Enter value for ename: pramod Enter value for job:
salesman Enter value for mgr: 5678 Enter value for sal:5000
Enter value for commission: 50
old 1: insert into employee values(&empno,'&ename','&job',&mgr,&sal,'&commission') new 1:
insert into employee values(105,'pramod','salesman',5678,5000,'50')
1 row created.
Name Type
Deptno Number
Deptname Varchar2(10)
Location Varchar2(10)
SOLUTION:
SQL> create table department(deptnonumber,deptname
varchar2(10),locationvarchar2(10)); Table created.
------------------- DEPTNO NU
MBER
DEPTNAME VARCHAR2(10)
LOCATION VARCHAR2(10)
DESIGNATION VARCHAR2(10)
1 row created.
SQL> /
1 row created.
SQL> /
Enter value for deptno: 11 Enter value for deptname:sales
Enter value for location: banglore Enter value for designation: salesman
old 1: insert into department values(&deptno,'&deptname','&location','&designation') new 1:
insert into department values(11,'sales','banglore','salesman')
1 row created.
SQL> /
Enter value for deptno: 12
Enter value for deptname: operations Enter value for location: mumbai Enter value for
designation: operator
old 1: insert into department values(&deptno,'&deptname','&location','&designation') new
1: insert into department values(12,'operations','mumbai','operator') 1
row created.
DEPTNO DEPTNAME
9 accounting
12 operations
10 research
11 sales
c. Update the record where deptno is9.
SQL> update department set designation='accountant' where
deptno=9; 2 rows updated.
SQL> select * from department;
DEPTNO DEPTNAME LOCATION DESIGNATION
9 accounting hyderabad
10 research chennai
11 sales banglore
12 operations mumbai
9 accounting Chennai
RESULT:
Thus the program to practice DDL commands in database has been donesuccessfully.
EXP.NO: 03
SOLUTION:
--Provide roles
--Assigning privileges
- EMPNO NOTNULL
NUMBER
ENAME NOT NULL
VARCHAR2(10) JOB
VARCHAR2(10) MANAGER_NO
NUMBER SALNUMBER
COMMISSION NUMBER
------------------- EMPNO
NOTNULL
NUMBER
ENAME NOTNULL VARCHAR2(10)
JOB NOTNULL
VARCHAR2(10)
MANAGER_NO SAL NUMBER NOT NULL
L NUMBER
COMMISSION NUMBER
SOLUTION:
create a user and grant all permissions to theuser.
--Provide roles
--Assigning privileges
rows selected.
DEPTNO NUMBER
DEPTNAME
VARCHAR2(10)
LOCATION NOT NULL
VARCHAR2(10)
RESULT: Thus the program to practice DDL and DML commands in database has been
done successfully.
EXP NO: 5
DATE: PROCEDURESANDFUNCTIONS
1) calculate the net salary and year salary if da is 30% of basic, hra is 10%
of basic and pf is 7% if basic salary is less than 8000, pf is 10% if basic sal
between 8000 to160000.
declare
e name varchar2(15);
basic number;
d a number; h r a number;
pf number;
net salary number; year
salary number; begin
e name:='&e name';
basic:=&basic; da:=basic *
(30/100); hra:=basic *
(10/100); if (basic < 8000)
then pf:=basic * (8/100);
elsif (basic >= 8000 and basic <= 16000) then
pf:=basic * (10/100);
end if;
netsalary:=basic + da + hra - pf; yearsalary := netsalary*12;
- l_input=31/01/1978
l_output=30
- l_input=30
l_output=3
-
Lucky=3
RESULT:
Thus the program to practice Pl/SQL commands in database has been donesuccessfully.
EXP NO:6 TRIGGERS
Date:
1. Create a row level trigger for the customers table that would fire for
INSERT or UPDATE or DELETE operations performed on the CUSTOMERS
table. This trigger will display the salary difference between the old values and
new values:
CUSTOMERS table:
Here following two points are important and should be noted carefully:
OLD and NEW references are not available for table level triggers, rather you can use them for
record leveltriggers.
If you want to query the table in the same trigger, then you should use the AFTER keyword,
because triggers can query the table or change it again only after the initial changes are
applied and the table is back in a consistent state.
Above trigger has been written in such a way that it will fire before any DELETE or INSERT
or UPDATE operation on the table, but you can write your trigger on a single or multiple
operations, for example BEFORE DELETE, which will fire whenever a record will be deleted
using DELETE operation on the table.
Let us perform some DML operations on the CUSTOMERS table. Here is one INSERT statement,
which will create a new record in the table:
INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY) VALUES (7, 'Kriti', 22,
'HP', 7500.00 );
When a record is created in CUSTOMERS table, above create trigger display_salary_changeswill be fired
and it will display the following result:
Old salary:
New salary: 7500 Salary difference:
Table created.
Trigger created.
SQL> insert into Employee(ID, First_Name, Last_Name, Start_Date, End_Date, Salary, City, Description)
2 values('01','Jason', 'Martin', to_date('19960725','YYYYMMDD'),
to_date('20060725','YYYYMMDD'), 1234.56, 'Toronto', 'Programmer')
3/
1 row created.
SQL> insert into Employee(ID, First_Name, Last_Name, Start_Date, End_Date, Salary, City, Description)
2 values('02','Alison', 'Mathews', to_date('19760321','YYYYMMDD'),
to_date('19860221','YYYYMMDD'), 6661.78, 'Vancouver','Tester')
3/
1 row created.
SQL> insert into Employee(ID, First_Name, Last_Name, Start_Date, End_Date, Salary, City,
Description)
2 values('03','James', 'Smith', to_date('19781212','YYYYMMDD'),
to_date('19900315','YYYYMMDD'), 6544.78, 'Vancouver','Tester')
3/
1 row created.
SQL> insert into Employee(ID, First_Name, Last_Name, Start_Date, End_Date, Salary, City,
Description)
2 values('04','Celia', 'Rice', to_date('19821024','YYYYMMDD'),
to_date('19990421','YYYYMMDD'), 2344.78,'Vancouver','Manager')
3/
1 row created.
SQL> insert into Employee(ID, First_Name, Last_Name, Start_Date, End_Date, Salary, City,
Description)
2 values('05','Robert', 'Black',
to_date('19840115','YYYYMMDD'),
to_date('19980808','YYYYMMDD'), 2334.78,
'Vancouver','Tester')
3/
1 row created.
SQL> insert into Employee(ID, First_Name, Last_Name, Start_Date, End_Date, Salary, City,
Description)
2 values('06','Linda', 'Green',
to_date('19870730','YYYYMMDD'),
to_date('19960104','YYYYMMDD'), 4322.78,'New
York','Tester')
3/
1 row created.
SQL> insert into Employee(ID, First_Name, Last_Name, Start_Date, End_Date, Salary, City,
Description)
2 values('07','David', 'Larry',
to_date('19901231','YYYYMMDD'),
to_date('19980212','YYYYMMDD'), 7897.78,'New
York','Manager')
3/
1 row created.
SQL> insert into Employee(ID, First_Name, Last_Name, Start_Date, End_Date, Salary, City,
Description)
2 values('08','James', 'Cat',
to_date('19960917','YYYYMMDD'),
to_date('20020415','YYYYMMDD'),
1232.78,'Vancouver','Tester') 3 /
1 row created. SQL>
select
* from
Employee 2
/
ID FIRST_NAME LAST_NAMESTART_DATEND_DATE SALARYCITY
DESCRIPTION
-
01 JASON Martin 25-JUL-96 25-JUL-06 1234.56 Toronto
Programm
e
r
02 ALISON Mathews 21-MAR-76 21-FEB-86 6661.78 Vancouver Tester
03 JAMES Smith 12-DEC-78 15-MAR-90 Vancouver Tester
6544.78
04 CELIA Rice 24-OCT-82 21-APR-99 2344.78 Vancouver Manager
05 ROBER Black 15-JAN-84 08-AUG-98 2334.78 Vancouver Tester
T
06 LINDA Green 30-JUL-87 04-JAN-96 4322.78 New YorkTester
07 DAVID Larry 31-DEC-90 12-FEB-98 7897.78 New York Manager
08 JAMES Cat 17-SEP-96 15-APR-02 1232.78 Vancouver Tester
8 rows selected.
/ Table dropped.
3) Trigger before deleting a record from emp table. Trigger will insert the
row to be deleted into another table and also record the user who has deleted
therecord.
Trigger created.
8 rows selected.
RESULT: Thus the program to practice triggers in Sql commands in database has been done
successfully.
EXP NO:7
Step1
Make sure you already downloaded the MySQL essential 5.0.45 win32.msi file. Double click on the
.msi file.
Step2
This is MySQL Server 5.0 setup wizard. The setup wizard will install MySQL Server 5.0 release 5.0.45 on
your computer. To continue, click next.
Step3
Choose the setup type that best suits your needs. For common program features select Typical
and it’s recommended for general use. To continue, click next.
Step4
This wizard is ready to begin installation. Destination folder will be in C:\Program Files\
MySQL\MySQL Server 5.0\. To continue, click next.
Step5
The program features you selected are being installed. Please wait while the setup wizard installs MySQL 5.0.
This may take several minutes.
Step6
To continue, click next.
Step7
To continue, click next.
Step8
Wizard Completed. Setup has finished installing MySQL 5.0. Check the configure the MySQL server
now to continue. Click Finish to exit the wizard
Step9
The configuration wizard will allow you to configure the MySQL Server 5.0 server instance.
To continue, click next.
Step10
Select a standard configuration and this will use a general purpose configuration for the server that can be
tuned manually. To continue, click next.
Step11:
Check on the install as windows service and include bin directory in windows path. To continue,
click next.
Step12:Please set the security options by entering the root password and confirm retype the password.
continue, click next.
Step15
Configuration file created. Windows service MySQL5 installed. Press finish to close the wizard.
Date: