0% found this document useful (0 votes)
7 views10 pages

Assignment 02

Uploaded by

skw2909
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views10 pages

Assignment 02

Uploaded by

skw2909
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

ASSIGNMENT – 02

SQL*Plus: Release 21.0.0.0.0 - Production on Sun Aug 11 00:08:38 2024

Version 21.3.0.0.0

Copyright (c) 1982, 2021, Oracle. All rights reserved.

Enter user-name: system

Enter password:

Last Successful login time: Tue Aug 06 2024 08:55:25 +05:30

Connected to:

Oracle Database 21c Express Edition Release 21.0.0.0.0 - Production

Version 21.3.0.0.0

1)Consider the following database where the primary keys are underlined. Create the following
tables in oracle

Person (driver_id, name, address)

Car (license, model, year)

Accident (report_no, date_acc, location)

Owns (driver_id, license)

Participated (driver_id, model, report_no, damage_amount)

SQL> create table person(driver_id int primary key,name varchar(20),address varchar(10));

Table created.

SQL> insert into person values(1001,'KUNAL','AHMEDNAGAR');

1 row created.

SQL> insert into person values(1002,'SANIKA','PUNE');

1 row created.

SQL> insert into person values(1003,'SHIVAM','LONAVALA');

1 row created.

SQL> insert into person values(1005,'SHUBHAM','PUNE');

1 row created.

SQL> insert into person values(1004,'RUSHIKESH','NAGPUR');

1 row created.

SQL> insert into person values(1006,'YASH','MUMBAI');

1 row created.
SQL> select * from person;

DRIVER_ID NAME ADDRESS

---------- -------------------- ----------

1001 KUNAL AHMEDNAGAR

1002 SANIKA PUNE

1003 SHIVAM LONAVALA

1005 SHUBHAM PUNE

1004 RUSHIKESH NAGPUR

1006 YASH MUMBAI

6 rows selected.

SQL> create table car(license varchar(15) primary key, model varchar(10),year int);

Table created.

SQL> insert into car values('SD124','HONDA',10001);

1 row created.

SQL> insert into car values('SD125','TOYOTA',10002);

1 row created.

SQL> insert into car values('SD126','BMW',10003);

1 row created.

SQL> insert into car values('SD127','BAJAJ',10004);

1 row created.

SQL> insert into car values('SD128','SUZUKI',10005);

1 row created.

SQL> select * from car;

LICENSE MODEL YEAR

--------------- ---------- ----------

SD124 HONDA 10001

SD125 TOYOTA 10002

SD126 BMW 10003

SD127 BAJAJ 10004

SD128 SUZUKI 10005

SQL> create table accident(report_no int primary key,date_acc date,location varchar(20));


Table created.

SQL> insert into accident values(10,'16/MAR/2018','LONAVALA');

1 row created.

SQL> insert into accident values(11,'19/MAY/2020','VASAI');

1 row created.

SQL> insert into accident values(12,'25/DEC/2022','DEVNAGAR');

1 row created.

SQL> insert into accident values(16,'04/JAN/2025','NASHIK FATA');

1 row created.

SQL> insert into accident values(17,'29/FEB/2024','NIGHOJ');

1 row created.

SQL> insert into accident values(18,'17/JUNE/2026','KESNAND PHATA');

1 row created.

SQL> select * from accident;

REPORT_NO DATE_ACC LOCATION

---------- --------- --------------------

10 16-MAR-18 LONAVALA

11 19-MAY-20 VASAI

12 25-DEC-22 DEVNAGAR

16 04-JAN-25 NASHIK FATA

17 29-FEB-24 NIGHOJ

18 17-JUN-26 KESNAND PHATA

6 rows selected.

SQL> create table participated(driver_id int primary key,model varchar(15),report_no int


,damage_amount int);

Table created.

SQL> insert into participated values(100,'HONDA',111,12000);

1 row created.

SQL> insert into participated values(101,'SUZUKI',111,24000);

1 row created.

SQL> insert into participated values(102,'HAMAHA',134,30000);


1 row created.

SQL> insert into participated values(103,'HYUNDRI',140,40000);

1 row created.

SQL> insert into participated values(104,'TOYOTA',142,45000);

1 row created.

SQL> insert into participated values(105,'BAJAJ',145,34000);

1 row created.

SQL> SELECT * FROM PARTICIPATED;

DRIVER_ID MODEL REPORT_NO DAMAGE_AMOUNT

---------- --------------- ---------- -------------

100 HONDA 111 12000

101 SUZUKI 111 24000

102 HAMAHA 134 30000

103 HYUNDRI 140 40000

104 TOYOTA 142 45000

105 BAJAJ 145 34000

6 rows selected.

SQL> create table owns(driver_id int primary key,license varchar(15));

Table created.

SQL> insert into owns values(1001,'SD121');

1 row created.

SQL> insert into owns values(1002,'SD122');

1 row created.

SQL> insert into owns values(1003,'SD123');

1 row created.

SQL> insert into owns values(1004,'SD124');

1 row created.

SQL> insert into owns values(1005,'SD125');

1 row created.

SQL> SELECT * FROM OWNS;


DRIVER_ID LICENSE

---------- ---------------

1001 SD121

1002 SD122

1003 SD123

1004 SD124

1005 SD125

SQL> create table Enployee(employee_name varchar(10) primary key, street varchar(20),city


varchar(20));

Table created.

SQL> insert into Enployee values('SNEHAL','STATION ROAD','LONAVALA');

1 row created.

SQL> insert into Enployee values('SHRUTI','PARK ROAD','PUNE');

1 row created.

SQL> insert into Enployee values('SALONI','VICTORIA ROAD','MUMBAI');

1 row created.

SQL> insert into Enployee values('SAKSHI','MAIN ROAD','NAGPUR');

1 row created.

SQL> insert into Enployee values('ASHWINI','MILL LANE','NASHIK');

1 row created.

SQL> SELECT * FROM ENPLOYEE;

EMPLOYEE_N STREET CITY

---------- -------------------- --------------------

SNEHAL STATION ROAD LONAVALA

SHRUTI PARK ROAD PUNE

SALONI VICTORIA ROAD MUMBAI

SAKSHI MAIN ROAD NAGPUR

ASHWINI MILL LANE NASHIK

SQL> create table works1(employee_name varchar(20) primary key,company_name


varchar(15),salary int);

Table created.
SQL> insert into works1 values('SHUBHAM','MICROSOFT',1000000);

1 row created.

SQL> insert into works1 values('YASH','GOOGLE',2000000);

1 row created.

SQL> insert into works1 values('SANKET','AMAZON',3000000);

1 row created.

SQL> insert into works1 values('NIKHIL','FLIPKARK',3500000);

1 row created.

SQL> insert into works1 values('VISHAL','ZUMPY',4500000);

1 row created.

SQL> SELECT * FROM WORKS1;

EMPLOYEE_NAME COMPANY_NAME SALARY

-------------------- --------------- ----------

SHUBHAM MICROSOFT 1000000

YASH GOOGLE 2000000

SANKET AMAZON 3000000

NIKHIL FLIPKARK 3500000

VISHAL ZUMPY 4500000

SQL> CREATE TABLE COMPANY1(COMPANY_NAME VARCHAR(15) PRIMARY KEY,CITY VARCHAR(20));

Table created.

SQL> insert into company1 values('GOOGLE','PUNE');

1 row created.

SQL> insert into company1 values('MICROSOFT','MUMBAI');

1 row created.

SQL> insert into company1 values('WIPRO','NASHIK');

1 row created.

SQL> insert into company1 values('AMAZON','NAGPUR');

1 row created.

SQL> insert into company1 values('VIROM','LATUR');

1 row created.

SQL> SELECT * FROM COMPANY1;


COMPANY_NAME CITY

--------------- --------------------

GOOGLE PUNE

MICROSOFT MUMBAI

WIPRO NASHIK

AMAZON NAGPUR

VIROM LATUR

SQL> create table Manages1(employee_name varchar(20) primary key,manager_name varchar(15));

Table created.

SQL> insert into Manages1 values('SAMYAK','PRADEEP');

1 row created.

SQL> insert into Manages1 values('YASH','SANTOSH');

1 row created.

SQL> insert into Manages1 values('NIKHIL','KISHOR');

1 row created.

SQL> insert into Manages1 values('ATHARVA','PRAVEEN');

1 row created.

SQL> insert into Manages1 values('RAMESH','VINAYAK');

1 row created.

SQL> SELECT * FROM MANAGES1;

EMPLOYEE_NAME MANAGER_NAME

-------------------- ---------------

SAMYAK PRADEEP

YASH SANTOSH

NIKHIL KISHOR

ATHARVA PRAVEEN

RAMESH VINAYAK

1) Create view with the employee_name, company_name by using above tables.

SQL> create view view1 as select employee_name,company_name from works;

View created.
SQL> select * from view1;

EMPLOYEE_NAME COMPANY_NAME

------------- -------------

SHUBHAM MICROSOFT

YASH GOOGLE

SANKET AMAZON

NIKHIL FLIPKARK

VISHAL ZUMPY

2) Create index for employee & participated table.

SQL> create index ind1 on participated(driver_id);

Index created.

SQL> select *from participated;

DRIVER_ID MODEL REPORT_NO DAMAGE_AMOUNT

---------- --------------- ---------- -------------

100 HONDA 111 12000

101 SUZUKI 111 24000

102 HAMAHA 134 30000

103 HYUNDRI 140 40000

104 TOYOTA 142 45000

105 BAJAJ 145 34000

6 rows selected.

3)Create sequence for person & insert 4 records using sequence.

SQL> create sequence s1 increment by 10 start with 1 maxvalue 50 nocycle;

Sequence created.

SQL> insert into person (driver_id) values (s1.nextval);

1 row created.

SQL> select* from person;

DRIVER_ID NAME ADDRESS

---------- -------------------- ----------

1001 KUNAL AHMEDNAGAR

1002 SANIKA PUNE


1003 SHIVAM LONAVALA

1005 SHUBHAM PUNE

1004 RUSHIKESH NAGPUR

1006 YASH MUMBAI

7 rows selected.

4) Create the synonym for table participated & company. Display the record using this table. Update
the record using the synonym tables.

SQL> create synonym s1_part for participated;

Synonym created.

SQL> select * from s1_part;

DRIVER_ID MODEL REPORT_NO DAMAGE_AMOUNT

---------- --------------- ---------- -------------

100 HONDA 111 12000

101 SUZUKI 111 24000

102 HAMAHA 134 30000

103 HYUNDRI 140 40000

104 TOYOTA 142 45000

105 BAJAJ 145 34000

SQL> update s1_part set damage_amount = 2500 where report_no = 111;

1 row updated.

SQL> select * from s1_part;

DRIVER_ID MODEL REPORT_NO DAMAGE_AMOUNT

---------- --------------- ---------- -------------

100 HONDA 111 12000

101 SUZUKI 111 24000

102 HAMAHA 134 30000

103 HYUNDRI 140 40000

104 TOYOTA 142 45000

105 BAJAJ 145 34000

You might also like