Download as pdf or txt
Download as pdf or txt
You are on page 1of 35

Name: Karan Sharma UID: 20BET1080

Section: DWWC-46 Subject: DBMS

Domain Winning Camp Worksheet (Practice Questions)


Day 1
Question1. Consider the following schema

ord_no purch_amt ord_date customer_id salesman_id

70001 150.5 2012-10-05 3005 5002

70009 270.65 2012-09-10 3001 5005

70002 65.26 2012-10-05 3002 5001

70004 110.5 2012-08-17 3009 5003

70007 948.5 2012-09-10 3005 5002

70005 2400.6 2012-07-27 3007 5001

70008 5760 2012-09-10 3002 5001

70010 1983.43 2012-10-10 3004 5006

70003 2480.4 2012-10-10 3009 5003

70012 250.45 2012-06-27 3008 5002

70011 75.29 2012-08-17 3003 5007

70013 3045.6 2012-04-25 3002 5001


1. Create the table orders with columns order_no number type, purch_amt
number(precision, scale), ord_date date, customer_id number and salesman_id
number
2. Insert the values as given in the table
3. Add customer name, email address and contact_number columns in the given
table
4. Add column gender in the table with single character value.
5. Update the values of newly added columns in the records.
6. Create another table orders_completed with ord_no, purch_amt, ord_date and
customer name, email_address and contact number. Then copy the information
of details from orders table where date is 10th October 2012.
Solution:
Code:
Ans 1.
create table Orders(
order_no number,
purch_amt number(6,2),
ord_date date,
customer_id number,
salesman_id number
);

Ans 2.
insert into Orders values(70001, 150.5, to_date('18-05-2012', 'DD-MM-YYYY'),3005,
5002);
insert into Orders values(70009, 270.65, to_date('09-10-2012', 'DD-MM-YYYY'),3001,
5005);
insert into Orders values(70002, 65.26, to_date('10-05-2012', 'DD-MM-YYYY'),3002,
5001);
insert into Orders values(70004, 110.5,to_date( '18-08-2012', 'DD-MM-YYYY'),3009,
5003);
insert into Orders values(70007, 948.5, to_date('09-10-2012', 'DD-MM-YYYY'),3005,
5002);
insert into Orders values(70005, 2400.6,to_date( '27-07-2012', 'DD-MM-YYYY'),3007,
5001);
insert into Orders values(70008, 5760,to_date( '09-10-2012', 'DD-MM-YYYY'),3002,
5001);
insert into Orders values(70010, 1983.43,to_date( '10-10-2012','DD-MM-YYYY'), 3004,
5006);
insert into Orders values(70003, 2480.4, to_date('10-10-2012', 'DD-MM-YYYY'),3009,
5003);
insert into Orders values(70012, 250.45, to_date('27-06-2012', 'DD-MM-YYYY'),3008,
5002);
insert into Orders values(70011, 75.29, to_date('17-08-2012', 'DD-MM-YYYY'),3003,
5007);
insert into Orders values(70013, 3045.6,to_date( '25-04-2012', 'DD-MM-YYYY'),3002,
5001);
select * from Orders;
Ans 3.
ALTER TABLE Orders ADD (
customer_name varchar(20),
email_address varchar(30),
contact_number number
);
Ans 4.
ALTER TABLE Orders ADD customer_gender char(1);
update Orders set customer_gender = 'F' where order_no<70020;
update Orders set customer_gender = 'M' where order_no = 70001;
select * from Orders;

Ans 5.
update Orders SET customer_name='Shruti', email_address ='shruti.2273@gmail.com',
contact_number='3652147248', customer_gender='F' where order_no='70001';
update Orders SET customer_name='Shreya', email_address ='shreya.2573@gmail.com',
contact_number ='5823758833', customer_gender='F' where order_no='70009';
update Orders SET customer_name='Deepak', email_address ='deepak.2119@gmail.com',
contact_number='9288132211',customer_gender='M' where order_no='70002';
update Orders SET customer_name='Shubham', email_address
='shubham.2382@gmail.com', contact_number ='7645474574', customer_gender='M' where
order_no='70004';
update Orders SET customer_name='Priya', email_address ='priya.9876@gmail.com',
contact_number='3127627647',customer_gender='F' where order_no='70007';
update Orders SET customer_name='Riya', email_address ='riya.2937@gmail.com',
contact_number='1928913889', customer_gender='F' where order_no='70005';
update Orders SET customer_name='Rashi', email_address ='rashi.9765@gmail.com',
contact_number='9654867488', customer_gender='F' where order_no='70008';
update Orders SET customer_name='Prateek', email_address ='prateek.9238@gmail.com',
contact_number ='9453845784', customer_gender='M' where order_no='70010';
update Orders SET customer_name='Kriti', email_address ='kriti.7347@gmail.com',
contact_number='3756738588', customer_gender='F' where order_no='70003';
update Orders SET customer_name='Soumya', email_address ='soumya.3344@gmail.com',
contact_number ='9342394734', customer_gender='F' where order_no='70012';
update Orders SET customer_name='Kush', email_address ='kush.7788@gmail.com',
contact_number='6875478457' , customer_gender='M' where order_no='70011';
update Orders SET customer_name='Shashank', email_address
='shashank.2061@gmail.com', contact_number ='6253264834', customer_gender='M' where
order_no='70013';
select * from Orders order by order_no;
Ans 6.
create Table orders_completed (
order_no number,
purch_amt number(6,2),
ord_date date,
customer_name varchar(20),
email_address varchar(30),
contact_number number
);
INSERT INTO orders_completed (order_no, purch_amt, ord_date, customer_name,
email_address, contact_number)
SELECT order_no, purch_amt, ord_date, customer_name, email_address, contact_number
FROM Orders WHERE ord_date = date '2012-10-10';
select * from orders_completed;
Question2. Consider the following schema

I FNAME LNAME GENDER SALARY HIREDATE

1 Rajveer Singh M 30000 2017/11/05

2 Manveer Singh M 50000 2017/11/05

3 Ashutosh Kumar M 40000 2017/12/12

4 Ankita Sharma F 45000 2017/12/15

5 Vijay Kumar M 50000 2018/01/12

6 Dilip Yadav M 25000 2018/02/26

7 Jayvijay Singh M 30000 2018/02/18

8 Reenu Kumari F 40000 2017/09/19

9 Ankit Verma M 25000 2018/04/04

10 Harpreet Singh M 50000 2017/10/10

1. Create table Employee.


2. Insert the values as mentioned.
3. Add column Employee ID as identity column.
4. Modify the column salary to store floating point values.
5. Rename the attribute FNAME to Emp_name.
6. Drop column LNAME from the employee table.
7. Add column Department with default value as ‘CSE’
8. Add an annual increment to the salary of employee whose joining date is 19th
September 2017.
9. Modify the department value of DILIP and VIJAY to ME
10. Delete the employees belonging to ME department

Solution:

Ans 1.

CREATE TABLE Employee ( ID INTEGER,

FNAME VARCHAR(20), LNAME VARCHAR(20), GENDER CHAR(1), SALARY


INTEGER, HIREDATE DATE

);

Ans 2.

INSERT INTO Employee VALUES(1,'RAJVEER','SINGH','M',30000,DATE '2017-11-


05');

INSERT INTO Employee VALUES(2,'MANVEER','SINGH','M',50000,DATE '2017-11-


05');

INSERT INTO Employee VALUES(3,'ASHUTOSH','KUMAR','M',40000,DATE '2017-12-


12');

INSERT INTO Employee VALUES(4,'ANKITA','SHARMA','F',45000,DATE '2017-12-


15');

INSERT INTO Employee VALUES(5,'VIJAY','KUMAR','M',50000,DATE '2018-01-12');

INSERT INTO Employee VALUES(6,'DILIP','YADAV','M',25000,DATE '2018-02-26');


INSERT INTO Employee VALUES(7,'JAYVIJAY','SINGH','M',30000,DATE '2018-02-
18');

INSERT INTO Employee VALUES(8,'REENU','KUMARI','F',40000,DATE '2017-09-19');

INSERT INTO Employee VALUES(9,'ANKIT','VERMA','M',25000,DATE '2018-04-04');

INSERT INTO Employee VALUES(10,'HARPREET','SINGH','M',50000,DATE '2017-10-


10');

select * from Employee;


Ans 3.

ALTER TABLE Employee ADD EMPLOYEE_ID INTEGER GENERATED BY


DEFAULT ON NULL AS IDENTITY START WITH 1;

Ans 5.

ALTER TABLE Employee MODIFY SALARY FLOAT;

Ans 6.

ALTER TABLE Employee RENAME COLUMN FNAME TO EMP_NAME;

select * from Employee;


Ans 7.

ALTER TABLE Employee DROP COLUMN LNAME;

Ans 8.

ALTER TABLE Employee ADD DEPARTMENT VARCHAR(20) DEFAULT('CSE');

select * from Employee;


Ans 9.

UPDATE Employee SET SALARY = SALARY + SALARY * 0.5 WHERE HIREDATE =


DATE '2017-09-19';

Ans 10.

UPDATE Employee SET DEPARTMENT='ME' WHERE EMP_NAME='DILIP';

UPDATE Employee SET DEPARTMENT='ME' WHERE EMP_NAME='VIJAY';

select * from Employee;


Q3. Consider the table in question 2

1. Apply Truncate command

2. Apply Drop command

3. Apply Delete command to delete all records at once.

Analyze the difference.

Solution:

Ans 1.
TRUNCATE TABLE EMPLOYEE;

TRUNCATE TABLE differs from DELETE in the following ways :

 TRUNCATE drops the table and re-create it. It is much faster than deleting rows one
by one.
 TRUNCATE removes all the rows from the Table.
 TRUNCATE does not return number of deleted rows.
 TRUNCATE is probably better thought of as a shortcut for DROP
TABLE/CREATE TABLE rather than a quirky kind of DELETE.
 TRUNCATE is a DDL command
 TRUNCATE is executed using a table lock and the whole table is locked to remove
all records.
 We cannot use the WHERE clause with TRUNCATE.
 Minimal logging in the transaction log, so it is faster performance-wise.
 TRUNCATE TABLE removes the data by deallocating the data pages used to store
the table data and records only the page deallocations in the transaction log.
 Identity the column is reset to its seed value if the table contains an identity column.

TRUNCATE is faster than DELETE.

2. DROP TABLE EMPLOYEE;

Drop table employee;

Create the table again and insert values. Identity column value will start from 1 Drop -
deletes the data as well as structure.

The difference between DROP and DELETE table is that, after executing DELETE
statement the contents of table are removed but the structure remains same, but in case of
DROP statement both the contents and structure are removed.
 The DROP command removes a table from the database.
 All the tables' rows, indexes, and privileges will also be removed.
 The operation cannot be rolled back with an exception in oracle 10g version onwards
by making use of flashback command.
 DROP and TRUNCATE are DDL commands, whereas DELETE is a DML
command.

3. DELETE FROM EMPLOYEE;

INSERT INTO EMPLOYEE VALUES(11,'HARPREET','SINGH','M',50000,DATE '2017-


10-10','');

Delete from employee where FNAME='DILIP' AND SALARY=25000;

The DELETE statement deletes table rows and returns number of rows deleted. we can
delete selected no of records from table using DELETE command.

 A DELETE is issued with no WHERE clause, all rows are deleted.


 ORDER BY clause can be used in DELETE statement. In this case, the rows are
deleted in the specified order.
 DELETE is a DML command.
 DELETE is executed using a row lock, each row in the table is locked for deletion.
 We can use where clause with DELETE to filter & delete specific records.
 The DELETE statement removes rows one at a time and records an entry in the
transaction log for each deleted row. As it maintains the log, so it slower than
TRUNCATE.
 Identity of column keep DELETE retains the identity.
 To use Delete you need DELETE permission on the table.
 Delete uses more transaction space than the Truncate statement.
Q4. Consider the following schema

|CUST_CODE | CUST_NAME | CUST_CITY | WORKING_AREA |


CUST_COUNTRY | GRADE | OPENING_AMT | RECEIVE_AMT | PAYMENT_AMT |
OUTSTANDING_AMT| PHONE_NO | AGENT_CODE |

+-----------+-------------+-------------+--------------+--------------+-------+-------------
+-------------+-------------+---------------+--------------+------------+

| C00013 | Holmes | London | London | UK | 2| 6000.00 | 5000.00 |


7000.00 | 4000.00 | BBBBBBB | A003 |

| C00001 | Micheal | New York | New York | USA | 2| 3000.00 |


5000.00 | 2000.00 | 6000.00 | CCCCCCC | A008 |

| C00020 | Albert | New York | New York | USA | 3| 5000.00 |


7000.00 | 6000.00 | 6000.00 | BBBBSBB | A008 |

| C00025 | Ravindran | Bangalore | Bangalore | India | 2| 5000.00 |


7000.00 | 4000.00 | 8000.00 | AVAVAVA | A011 |

| C00024 | Cook | London | London | UK | 2| 4000.00 | 9000.00 |


7000.00 | 6000.00 | FSDDSDF | A006 |

| C00015 | Stuart | London | London | UK | 1| 6000.00 | 8000.00 |


3000.00 | 11000.00 | GFSGERS | A003 |

| C00002 | Bolt | New York | New York | USA | 3| 5000.00 |


7000.00 | 9000.00 | 3000.00 | DDNRDRH | A008 |

| C00018 | Fleming | Brisban | Brisban | Australia | 2| 7000.00 | 7000.00 |


9000.00 | 5000.00 | NHBGVFC | A005 |

| C00021 | Jacks | Brisban | Brisban | Australia | 1| 7000.00 | 7000.00 |


7000.00 | 7000.00 | WERTGDF | A005 |

| C00019 | Yearannaidu | Chennai | Chennai | India | 1| 8000.00 | 7000.00


| 7000.00 | 8000.00 | ZZZZBFV | A010 |

| C00005 | Sasikant | Mumbai | Mumbai | India | 1| 7000.00 | 11000.00


| 70f00.00 | 11000.00 | 147-25896312 | A002 |
| C00007 | Ramanathan | Chennai | Chennai | India | 1| 7000.00 |
11000.00 | 9000.00 | 9000.00 | GHRDWSD | A010 |

| C00022 | Avinash | Mumbai | Mumbai | India | 2| 7000.00 |


11000.00 | 9000.00 | 9000.00 | 113-12345678 | A002 |

| C00004 | Winston | Brisban | Brisban | Australia | 1| 5000.00 | 8000.00 |


7000.00 | 6000.00 | AAAAAAA | A005 |

| C00023 | Karl | London | London | UK | 0| 4000.00 | 6000.00 |


7000.00 | 3000.00 | AAAABAA | A006 |

| C00006 | Shilton | Torento | Torento | Canada | 1| 10000.00 | 7000.00 |


6000.00 | 11000.00 | DDDDDDD | A004 |

| C00010 | Charles | Hampshair | Hampshair | UK | 3| 6000.00 |


4000.00 | 5000.00 | 5000.00 | MMMMMMM | A009 |

| C00017 | Srinivas | Bangalore | Bangalore | India | 2| 8000.00 | 4000.00 |


3000.00 | 9000.00 | AAAAAAB | A007 |

| C00012 | Steven | San Jose | San Jose | USA | 1| 5000.00 | 7000.00 |


9000.00 | 3000.00 | KRFYGJK | A012 |

| C00008 | Karolina | Torento | Torento | Canada | 1| 7000.00 | 7000.00 |


9000.00 | 5000.00 | HJKORED | A004 |

| C00003 | Martin | Torento | Torento | Canada | 2| 8000.00 | 7000.00 |


7000.00 | 8000.00 | MJYURFD | A004 |

| C00009 | Ramesh | Mumbai | Mumbai | India | 3| 8000.00 | 7000.00


| 3000.00 | 12000.00 | Phone No | A002 |

| C00014 | Rangarappa | Bangalore | Bangalore | India | 2| 8000.00 |


11000.00 | 7000.00 | 12000.00 | AAAATGF | A001 |

| C00016 | Venkatpati | Bangalore | Bangalore | India | 2| 8000.00 |


11000.00 | 7000.00 | 12000.00 | JRTVFDD | A007 |

| C00011 | Sundariya | Chennai | Chennai | India | 3| 7000.00 | 11000.00


| 7000.00 | 11000.00 | PPHGRTS | A010 |
+-----------+-------------+-------------+--------------+--------------+-------+-------------
+-------------+-------------+---------------+--------------+------------+

Create the table Customer_details with following columns

CUST_CODE
CUST_NAME
CUST_CITY
WORKING_AREA
CUST_COUNTRY
GRADE
OPENING_AMT
RECEIVE_AMT
PAYMENT_AMT
OUTSTANDING_AMT
PHONE_NO
AGENT_CODE

Insert the values as shown in the table

Perform following operations on the above table


1. Modify phone number column to number data type.
2. Update the values of all records corresponding to newly added columns.
3. Add Gender column in single char value.
4. Add order_time column of timestamp type.
5. Update the outstanding amount to 0 for all customers from India.
6. View all the Britishers whose outstanding amount is greater than 7000.
7. Add column feedback with clob data type.
8. Remove all customers with grade 2.

Solution:
Create TABLE customer_details ( CUST_CODE varchar(15), CUST_NAME varchar(50),
CUST_CITY varchar(50), WORKING_AREA varchar(50), CUST_COUNTRY
varchar(50), GRADE NUMBER, OPENING_AMT float, RECEIVE_AMT float,
PAYMENT_AMT float, OUTSTANDING_AMT float, PHONE_NO varchar(20),
AGENT_CODE varchar(10));
select * from customer_details;

INSERT ALL
INTO customer_details VALUES
('C00013','Holmes','London','London','UK',2,6000.00,5000.00,7000.00,4000.00,'BBBBBBB'
,'A003')
INTO customer_details VALUES ('C00001','Micheal','New York','New
York','USA',2,3000.00,5000.00,2000.00,6000.00,'CCCCCCC','A008')
INTO customer_details VALUES ('C00020','Albert','New York','New
York','USA',3,5000.00,7000.00,6000.00,6000.00,'BBBBSBB','A008')
INTO customer_details VALUES
('C00025','Ravindran','Bangalore','Bangalore','India',2,5000.00,7000.00,4000.00,8000.00,'A
VAVAVA','A011')
INTO customer_details VALUES
('C00024','Cook','London','London','UK',2,4000.00,9000.00,7000.00,6000.00,'FSDDSDF','A
006')
INTO customer_details VALUES
('C00015','Stuart','London','London','UK',1,6000.00,8000.00,3000.00,11000.00,'GFSGERS','
A003')
INTO customer_details VALUES ('C00002','Bolt','New York','New
York','USA',3,5000.00,7000.00,9000.00,3000.00,'DDNRDRH','A008')
INTO customer_details VALUES
('C00018','Fleming','Brisban','Brisban','Australia',2,7000.00,7000.00,9000.00,5000.00,'NHB
GVFC','A005')
INTO customer_details VALUES
('C00021','Jacks','Brisban','Brisban','Australia',1,7000.00,7000.00,7000.00,7000.00,'WERTG
DF','A005')
INTO customer_details VALUES ('C00019
','Yearannaidu','Chennai','Chennai','India',1,8000.00,7000.00,7000.00,8000.00,'ZZZZBFV','
A010')
INTO customer_details VALUES
('C00005','Sasikant','Mumbai','Mumbai','India',1,7000.00,11000.00,7000.00,11000.00,'147-
25896312','A002')
INTO customer_details VALUES
('C00007','Ramanathan','Chennai','Chennai','India',1,7000.00,11000.00,9000.00,9000.00,'G
HRDWSD','A010')
INTO customer_details VALUES
('C00022','Avinash','Mumbai','Mumbai','India',2,7000.00,11000.00,9000.00,9000.00,' 113-
12345678','A002')
INTO customer_details VALUES
('C00004','Winston','Brisban','Brisban','Australia',1,5000.00,8000.00,7000.00,6000.00,'AAA
AAAA','A005')
INTO customer_details VALUES
('C00023','Karl','London','London','UK',0,4000.00,6000.00,7000.00,3000.00,'AAAABAA','
A006')
INTO customer_details VALUES
('C00006','Shilton','Torento','Torento','Canada',1,10000.00,7000.00,6000.00,11000.00,'DDD
DDDD','A004')
INTO customer_details VALUES
('C00010','Charles','Hampshair','Hampshair','UK',3,6000.00,4000.00,5000.00,5000.00,'MM
MMMMM','A009')
INTO customer_details VALUES
('C00017','Srinivas','Bangalore','Bangalore','India',2,8000.00,4000.00,3000.00,9000.00,'AA
AAAAB','A007')
INTO customer_details VALUES ('C00012','Steven','San Jose','San
Jose','USA',1,5000.00,7000.00,9000.00,3000.00,'KRFYGJK','A012')
INTO customer_details VALUES
('C00008','Karolina','Torento','Torento','Canada',1,7000.00,7000.00,9000.00,5000.00,'HJKO
RED','A004')
INTO customer_details VALUES
('C00003','Martin','Torento','Torento','Canada',2,8000.00,7000.00,7000.00,8000.00,'MJYUR
FD','A004')
INTO customer_details VALUES
('C00009','Ramesh','Mumbai','Mumbai','India',3,8000.00,7000.00,3000.00,12000.00,' 113-
1263343','A002')

INTO customer_details VALUES


('C00014','Rangarappa','Bangalore','Bangalore','India',2,8000.00,11000.00,7000.00,12000.00
,' AAAATGF','A001')
INTO customer_details VALUES
('C00016','Venkatpati','Bangalore','Bangalore','India',2,8000.00,11000.00,7000.00,12000.00,
' JRTVFDD','A007')
INTO customer_details VALUES
('C00011','Sundariya','Chennai','Chennai','India',3,8000.00,11000.00,7000.00,11000.00,'
PPHGRTS','A010')
SELECT * FROM dual;

Ans 1.
Alter Table customer_details MODIFY phone_no number;

update customer_details SET phone_no =NULL; Alter Table customer_details


MODIFY phone_no number;

Ans 2.
update customer_details SET phone_no = 8674653895 where cust_code='C00001'; update
customer_details SET phone_no = 6576768546 where cust_code='C00002'; update
customer_details SET phone_no = 9377843774 where cust_code='C00003'; update
customer_details SET phone_no = 6347845393 where cust_code='C00004'; update
customer_details SET phone_no = 7695487683 where cust_code='C00005'; update
customer_details SET phone_no = 7869543476 where cust_code='C00006';

update customer_details SET phone_no = 9238476538 where cust_code='C00007'; update


customer_details SET phone_no = 9878349586 where cust_code='C00008'; update
customer_details SET phone_no = 9876746587 where cust_code='C00009'; update
customer_details SET phone_no = 8784686576 where cust_code='C00010'; update
customer_details SET phone_no = 9386477985 where cust_code='C00011'; update
customer_details SET phone_no = 9732587989 where cust_code='C00012'; update
customer_details SET phone_no = 9349588457 where cust_code='C00013'; update
customer_details SET phone_no = 9758653595 where cust_code='C00014'; update
customer_details SET phone_no = 8907234323 where cust_code='C00015'; update
customer_details SET phone_no = 9398358527 where cust_code='C00016'; update
customer_details SET phone_no = 6450768546 where cust_code='C00017'; update
customer_details SET phone_no = 8574378839 where cust_code='C00018'; update
customer_details SET phone_no = 5379879857 where cust_name='Yearannaidu'; update
customer_details SET phone_no = 9856383543 where cust_code='C00020'; update
customer_details SET phone_no = 3366489876 where cust_code='C00021'; update
customer_details SET phone_no = 8947039864 where cust_code='C00022'; update
customer_details SET phone_no = 0983764587 where cust_code='C00023'; update
customer_details SET phone_no = 7864587995 where cust_code='C00024'; update
customer_details SET phone_no = 4579436960 where cust_code='C00025'; select * from
customer_details order by cust_code;
3. ALTER TABLE customer_details ADD cust_gender varchar(1);
update customer_details SET cust_gender='M'; select * from customer_details order by
cust_code;

4. ALTER TABLE customer_details ADD order_time TIMESTAMP;


select DBTIMEZONE from dual;
5. update customer_details SET outstanding_amt=0 where cust_country ='India';

6. select * from customer_details where cust_country='UK' AND


outstanding_amt>7000 order by cust_code;

7. // CLOB datatype is used to add paragraph.


ALTER TABLE customer_details ADD feedback CLOB; update customer_details SET
feedback='Large text space' ; select * from customer_details order by cust_code
8. DELETE FROM customer_details WHERE grade =2 ;

Question5. Create table EMP with the following description :


Name Type
EMPNO NOT NULL NUMBER(4)
ENAME VARCHAR2(10)
JOB VARCHAR2(9)
MGR NUMBER(4)
HIREDATE DATE
SAL NUMBER(7,2)
COMM NUMBER(7,2)
DEPTNO NUMBER(3)
AGE NUMBER(3)

1. Insert 5 records as shown in table below-

2. List all employee names , salary , 15% rise as ‘Raise’ and Rised amount after 15% as
Raised_Amount in salary.
3.. Insert the following record in employee table-
(6,’ ‘, HR,2345,12-12-2020, 45000,40,20,32)
(7,George, Research,,2480,01-01-2018, 55000,’ ‘,25,42)
4. List ename, job where employee name is NULL
5.List ename whose manager is not NULL.
6. Find no.of dept in employee table.
7. List ename whose commission is NULL.
8. Display ename of the dept. with deptno 30.

Solution:
create table EMP (
EMPNO number(4) NOT NULL,
ENAME varchar2(10), JOB varchar2(9), MGR number(4), HIREDATE date, SAL
number(7,2), COMM number(7,2), DEPTNO number(3), AGE number(3)
);

1. Insert 5 records as shown in table –

insert into EMP values (1,'karan','HR',1567,date '2017-12-1', 50000, 1,33,34); insert into
EMP values (2,'Varun','Analyst',2983,date '2018-1-5', 25000.5,5,25,27); insert into EMP
values (3,'Ajay','Research',4253,date '2019-4-20', 20000, 6,23,33);
insert into EMP values (4,'Ashish','Trainer',1103,date '2015-06-30', 40000, 8,28,40);

insert into EMP values (5,'Adarsh','Executive',6140,date '2020-09-15', 10000, 11,30,26);

2. List all employee names , salary , 15% rise as ‘Raise’ and Rised amount after 15% as
Raised_Amount in salary.

select ENAME, SAL, (SAL*.15) as Raise from EMP;


select ENAME, SAL,SAL*.15 as Raise, SAL+(SAL*.15) as Raised_Amount from EMP;

3. Insert the following record in employee table- (6,’ ‘, HR,2345,12-12-2020,


45000,40,20,32)
(7,George, Research,,2480,01-01-2018, 55000,’ ‘,25,42)

Insert into EMP values(6,NULL,'HR',2345,date '2020-12-12', 45000,40,20,32);


Insert into EMP values(7,'George', 'Research',2480,date '2018-01-01',55000,NULL,25,42);

4. List ename, job where employee name is NULL


select ENAME,JOB from EMP where ENAME is NULL;

5. List ename whose manager is not NULL.


select ENAME from EMP where MGR is NOT NULL;

6. Find no.of dept in employee table. select count(DEPTNO) from EMP;

7. List ename whose commission is NULL.


select ENAME from EMP where COMM is NULL;

8. Display ename of the dept. with deptno 30. select ENAME from EMP where
DEPTNO = 30;
Question6. Consider the visitor table data-

VisitorID VisitorName Gender ComingFrom AmountPaid

1 Suman F Kanpur 5000

2 Indu F Lucknow 4500

3 Rachana F Haryana 3000

4 Vikram M Kanpur 2000

5 Rajesh M Kanpur 4000

6 Suresh M Lucknow 3000

7 Dinesh M Varanasi

8 Shikha F Chandigarh 3600

Perform following operations on the above table

1. Create a table in which VisitorID will be an auto-increment column.


2. Insert data of VisitorName, Gender, ComingFrom and AmountPaid as shown in table.
3. Write a query to display VisitorName, Coming from details of Female Visitors with
Amount Paid more than 3500.
4. Write a query to fetch the data of those visitors whose AmountPaid is NULL.
5. Write a query to update the column name ‘COMINGFROM’ to ‘CITY’
6. Write a query to Delete the data from column ‘AmountPaid’.
7. Write a query to check the system date from the DUAL table.

Solution:
1. Create a table in which VisitorID will be an auto-increment column. CREATE
TABLE visitor (
VisitorID NUMBER GENERATED ALWAYS AS IDENTITY,
VisitorName varchar(10), Gender char(1), ComingFrom Varchar(15), AmountPaid
number);
2. Insert data of VisitorName, Gender, ComingFrom and AmountPaid as shown in
table.
insert into visitor (VisitorName,Gender,ComingFrom,AmountPaid) values
('Suman','F','Kanpur',5000); insert into visitor
(VisitorName,Gender,ComingFrom,AmountPaid) values ('Indu','F','Lucknow',4500); insert
into visitor (VisitorName,Gender,ComingFrom,AmountPaid) values
('Rachana','F','Haryana',3000); insert into visitor
(VisitorName,Gender,ComingFrom,AmountPaid) values ('Vikram','M','Kanpur',2000);
insert into visitor (VisitorName,Gender,ComingFrom,AmountPaid) values
('Rajesh','M','Kanpur',4000); insert into visitor
(VisitorName,Gender,ComingFrom,AmountPaid) values ('Suresh','M','Lucknow',3000);
insert into visitor (VisitorName,Gender,ComingFrom) values ('Dinesh','M','Varanasi');
insert into visitor (VisitorName,Gender,ComingFrom,AmountPaid) values
('Shikha','F','Chandigarh',3600);

3. Write a query to display VisitorName, Coming from details of Female Visitors with
Amount Paid more than 3500.
Select VisitorName from visitor where gender='F' and AmountPaid>3500;

4. Write a query to fetch the data of those visitors whose AmountPaid is NULL. Select
* from visitor where AMOUNTPAID IS NULL;
5. Write a query to update the column name ‘COMINGFROM’ to ‘CITY’ alter table
visitor rename column ComingFrom to city;

6. Write a query to Delete the data from column ‘AmountPaid’. Update visitor set
AmountPaid=NULL;

7. Write a query to check the system date from the DUAL table. SELECT sysdate
FROM DUAL ;
Question7. Explain 3-tier architecture in DBMS.
The 3-tier architecture contains one more layer between the client and the server.
 In this architecture, there is no direct communication between client and server.
 Mainly, the 3-tier is used for large applications on the web.
 The features of 3-tier architecture are data backup, recovery, security, and concurrency
control.

Layers
The 3-tier architecture consists of the three layers as follows −
 Presentation layer − This layer is also called the client layer. The front-end layer
consists of a user interface. The main purpose is to communicate with the application
layer.
 Application layer − This layer is also called the business logic layer. It acts as a middle
layer between the client and the database server which are used to exchange partially
processed data.
 Database layer − In this layer the data or information is stored. This layer performs
operations like insert, update and delete to connect with the database.

The Tier-3 Architecture is diagrammatically represented below –

You might also like