1,2,3,4
1,2,3,4
1.Create table employee using SQL command to store details of employee. Such as empno,
name, designation, department, gender, and salary. Specify primary key and not null
constraints on the table.
Allow only ‘M’ or ‘F’ for the column gender.
Department can be sales, accounts, IT.
Choose designation as clerk, analyst, manager, accountant and supervisor that depends on
department.
Write the following SQL quries:
A) Display EMPNO,NAME and DESIGNATION of all employees whose name ends
with RAJ.
B) Display the details of all female employees who is earning salary within the range
20000 to 40000 in SALES or IT departments.
C) List the different DEPARTMENTs with the DISGNATIONs in that department.
D) Display the department name,total,average,maximum,minimumsalary of the
DEPARTMENT only if the total salary given in that department is more than
30000.
E) List the departments which have more than 2 employees.
Structure of Table:
1 row created.
B) Display the details of all female employees who is earning salary within the range
20000 to 40000 in SALES or IT departments.
SQL> select *from emp12345 where gender ='F' and (salary between 20000 and 40000)and
department in('sales','IT');
EMP_NO NAME G DEPARTMENT DESIGNATIO SALARY
---------- ----- - ---------- ---------- ----------
110 megha F IT manager 30000
114 geeta F IT clerk 25000
115 rose F sales clerk 28000
2. Create a table CLIENT to store Client_no, Name, Address, State, Bal_Due. Client no must
start with ‘C’. Apply the suitable structures for the columns. Specify primary key and NOT
NULL constraints on the table.
Insert 10 records.
Write the following SQL queries:
a) From the table CLIENT, create a new table CLIENT1 that contains only CLIENT_NO and
NAME, BAL_DUE from specified STATE. Accept the state during run time.
b) create a new table CLIENT2 that has the same structure as CLIENT but with no records.
Display the structure and records.
c) Add a new column by name PENALTY number (10, 2) to the CLIENT.
d) Assign Penalty as 10% of BAL_DUE for the clients C1002, C1005, C1009 and for others
8%. Display Records.
e) Change the name of CLIENT1 as NEW_CLIENT.
f) Delete the table CLIENT2.
Creating Table:
create table client(clientno varchar(10) primary key,
name varchar(10) not null,
adress varchar(20) not null,
state varchar(10) not null,
bal_due number(7),
check (clientno like 'C%'));
Displaying Table:
b) create a new table CLIENT2 that has the same structure as CLIENT but with no
records. Display the structure and records.
SQL> create table client2 (clientno,name,adress,state,bal_due) as select
clientno,name,adress,state,bal_due from client where 1=2;
Table created.
d) Assign Penalty as 10% of BAL_DUE for the clients C1002, C1005, C1009 and for
others 8%. Display Records.
SQL> update client set penalty = 0.1*bal_due where clientno in('C1001','C1005','C1009');
3 rows updated.
SQL> update client set penalty = 0.08*bal_due where clientno not in('C1001','C1005','C1009');
7 rows updated.
Table dropped.
3. Create a table BOOK using SQL command to store Accession No, TITLE, AUTHOR,
PUBLISHER, YEAR, PRICE. Apply the suitable structure for the columns. Specify Primary
Key and NOT NULL constraints on the table. Insert 10 records.
Write the following SQL queries:
a) List the details of publishers having ‘a’ as the second character in their names.
b) Display Accession No., TITLE, PUBLISHER and YEAR of the books published by the
specified author before 2010 in the descending order of YEAR. Accept author during
runtime.
c) Modify the size of TITLE to increase the size 5 characters more.
d) Display the details of all books other than Microsoft press publishers.
e) Remove the records of the books published before 1990.
Creating Table:
SQL> create table book480(
2 accession_no number(5) primary key,
3 title varchar(20) not null,
4 author varchar(20) not null,
5 publisher varchar(20) not null,
6 year number(4) not null,
7 price number(10,2) not null);
Table created
Describing Table:
SQL> desc book480;
Displaying table:
SQL> select *from book480;
a) List the details of publishers having ‘a’ as the second character in their names.
SQL> select *from book480 where publisher like '_a%';
b) Display Accession No., TITLE, PUBLISHER and YEAR of the books published by the
specified author before 2010 in the descending order of YEAR. Accept author during
runtime.
SQL> select accession_no,title,publisher,year from book480 where(year<2010 and
author='&author')order by year desc;
Enter value for author: David
old 1: select accession_no,title,publisher,year from book480 where(year<2010 and
author='&author')order by year desc
new 1: select accession_no,title,publisher,year from book480 where(year<2010 and
author='David')order by year desc
d) Display the details of all books other than Microsoft press publishers.
SQL> select *from book480 where publisher not in('Microsoft Press');
Inserting values:
SQL> insert into sale(sno,sname,DOJ,DOB,salary,sales_amount)values('C1001','sai','12-jan-
14','12-may-91',49000,24000);
a) Display the details of Sales Persons whose salary is more than Average salary in the
company.
select *from sale where salary > (select avg(salary) from sale);