Professional Documents
Culture Documents
DBMS Day 1 Karan
DBMS Day 1 Karan
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
Solution:
Ans 1.
);
Ans 2.
Ans 5.
Ans 6.
Ans 8.
Ans 10.
Solution:
Ans 1.
TRUNCATE TABLE EMPLOYEE;
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.
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.
The DELETE statement deletes table rows and returns number of rows deleted. we can
delete selected no of records from table using DELETE command.
+-----------+-------------+-------------+--------------+--------------+-------+-------------
+-------------+-------------+---------------+--------------+------------+
CUST_CODE
CUST_NAME
CUST_CITY
WORKING_AREA
CUST_COUNTRY
GRADE
OPENING_AMT
RECEIVE_AMT
PAYMENT_AMT
OUTSTANDING_AMT
PHONE_NO
AGENT_CODE
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')
Ans 1.
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';
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)
);
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);
2. List all employee names , salary , 15% rise as ‘Raise’ and Rised amount after 15% as
Raised_Amount in salary.
8. Display ename of the dept. with deptno 30. select ENAME from EMP where
DEPTNO = 30;
Question6. Consider the visitor table data-
7 Dinesh M Varanasi
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.