DBM Sprint
DBM Sprint
DBM Sprint
1.create table
2.alter table
3.drop table
Deptno int,
Dname varchar(10),
loc varchar(4),
primary key(Deptno)
);
OUTPUT:
Table altered.
OUTPUT:
1 Devlopment nash
2 Testing pune
3 production pimp
4 management pune
5 marketing goa
6 HR USA
7 Sales UK
8 Sr.maneger mumb
#Add the new column pincode with not null constraint to the existing
thable Department:
SQL: Alter table Department Add(pincode number(6));
Table Column Data Type Length Precision Scale Primary Key Nullable
Default Comment
1-4
OUTPUT:
Table dropped.
OUTPUT:
Table altered.
SQL:
desc Department;
OUTPUT:
Table Column Data Type Length Precision Scale Primary Key Nullable
Default Comment
1-3
OUTPUT:
Table dropped.
1.insert
2.update
3.delete
E_NAME VARCHAR(20),
E_ADDRESS VARCHAR(20),
E_PH NUMBER(10),
DEPT_NO VARCHAR(10),
DEPT_NAME VARCHAR(15),
JOB_ID CHAR(10),
SALARY NUMBER(20)
);
3.Display Table:
EMP_NO E_NAME E_ADDRESS E_PH DEPT_NO DEPT_NAME JOB_ID SALARY
UPDATE EMPLOYE1
WHERE EMP_NO = 5;
OUTPUT
EMP_NO E_NAME E_ADDRESS E_PH DEPT_NO DEPT_NAME JOB_ID SALARY
5.Select querry:
SQL:
OUTPUT:
E_NAME SALARY
RAM 25000
Raghu 55000
Raghunat 40000
vishnu 60000
Tejas 70000
Sujal 80000
OUTPUT:
Table dropped.
1.number function
2.aggregate function
3.character function
4.conversion function
5.date function
1st
List the E_no, E_name, Salary of all employees working for MANAGER
select eno,ename,salary
from emp1
where designation='Manager';
1 Hrishikesh 15000
2 Soham 25000
2nd
Display all the details of the employee whose salary is more than the Sal of any IT PROFF..
3rd
List the employees in the ascending order of Designations of those joined after 1981.
where doj>'01-jan-1981'
order by designation
ENAME
----------
Ramesh
Rohan
mahesh
sumit
tanmay
Soham
Hrishikesh
4th
List the employees along with their Experience and Daily Salary.
5th
or designation='Analyst'
order by doj
7th
ENAME
--------
Rohan
Ramesh
sumit
mahesh
mahesh
8th
ENAME
----------
Soham'
9th
Display the name as well as the first five characters of name(s) starting with ‘H’
ENAME
----------
Hrishikesh
10
List all the emps except ‘PRESIDENT’ & ‘MGR” in asc order of Salaries.(JOA,ANALY MENTION IN RECORDS)
order by salary
ENAME
----------
Ramesh
Rohan
mahesh
sumit
tanmay
Soham
Hrishikesh
1.arithmatic operator
2.logical operator
3.comparison operator
4.special operator
5.set operator
create table emp2(eid int primary key,ename varchar(20),deptid int references dept(deptid))
1st: Display all the dept numbers available with the dept and emp tables avoiding duplicates.
DEPTID
----------
10
2nd:Display all the dept numbers available with the dept and emp tables.
select deptid from emp2 union all select deptid from dept
DEPTID
----------------
3
3
10
3rd:Display all the dept numbers available in emp and not in dept tables and vice versa.
DEPTID
----------
10
1.inner join
2.outer join
3.natural join...etc
create table sailor(sid int primary key, sname varchar(20), rating int, age int)
create table boats (bid int primary key, bname varchar(20), color varchar(20))
create table reserve(sid int references sailor(sid), bid int references boats(bid), day date)
1. Find all information of sailors who have reserved boat number 101
select *
from sailor s
where r.bid=101
SELECT b.bname
FROM sailor s
JOIN reserve r ON s.sid = r.sid
BNAME
--------------------
Big boat
Small_ship
Small_ship
3.Find the names of sailors who have reserved a red boat, and list in the order of age
SELECT s.sname
FROM sailor s
order by age';
SNAME
-----------
Bob
4.Find the names of sailors who have reserved at least one boat.
FROM sailor s
--------------------
Wood
Bob
Jhon
David
5. Find the ids and names of sailors who have reserved two different boats on the same day.
FROM sailor s
JOIN reserve r2 ON s.sid = r2.sid AND r1.day = r2.day AND r1.bid <> r2.bid
SID SNAME
---------- --------------------
101 Jhon
102 Bob
101 Jhon
102 Bob
6. Find the ids of sailors who have reserved a red boat or a green boat.
SID SNAME
---------- --------------------
102 Bob
103 David
101 Jhon
104 Wood
FROM sailor s
SNAME AGE
-------------------- ----------
Wood 21
FROM sailor s;
COUNT(DISTINCTS.SNAME)
----------------------
FROM sailor
GROUP BY rating;
RATING AVERAGE_AGE
---------- -----------
8 29
7 46
9 21
10. Find the average age of sailors for each rating level that has at least two sailors.
FROM sailor
GROUP BY rating
RATING AVERAGE_AGE
---------- -----------
8 29
2.orderby clause
3.indexing
SUM(SALARY) DNAME
----------- --------------------
40000 Administration
40000 Purchasing
38000 IT
-----------
20000
12000
14000
3. Display number of employees working in each department and their department name
COUNT(*) DNAME
--------- --------------------
2 Administration
2 Purchasing
1 Human Resources
2 IT
7 rahul 5 24000
2 sumit 1 20000
3 rohan 3 20000
1 Mohit 1 20000
4 mohan 3 20000
6 soham 5 14000
5 khushi 4 12000
5. Show the record of employee earning salary greater than 16000 in each department.
select * from dept,emp2 where dept.deptid=emp2.deptid and salary>16000 group by dname group by dname
5 IT Mumbai 411002
1.subquerries
2.views
create table sailor(sid int primary key, sname varchar(20), rating int, age int)
create table boats (bid int primary key, bname varchar(20), color varchar(20))
create table reserve(sid int references sailor(sid), bid int references boats(bid), day date)
1. Find all information of sailors who have reserved boat number 101
BNAME
------------------
Small_boat
Big boat
Small_ship
Small_ship
Small_boat
Small_ship
Small_ship
3.Find the names of sailors who have reserved a red boat, and list in the order of age
SNAME AGE
-------------------- ----------
Bob 26
4.Find the names of sailors who have reserved at least one boat.
SNAME
------
Wood
Bob
Jhon
5. Find the ids and names of sailors who have reserved two different boats on the same day.
FROM sailor s
JOIN reserve r2 ON s.sid = r2.sid AND r1.day = r2.day AND r1.bid <> r2.bid
SID SNAME
---------- --------------------
101 Jhon
102 Bob
101 Jhon
102 Bob
6. Find the ids of sailors who have reserved a red boat or a green boat.
SID SNAME
------ ------
102 Bob
103 David
101 Jhon
104 Wood
SNAME
------
Wood
Bob
Jhon
David
AVG(AGE) RATING
---------- ----------
29 8
46 7
21 9
10. Find the average age of sailors for each rating level that has at least two sailors.
select avg(age),rating from sailor group by rating having count(*)>1;
AVG(AGE) RATING
---------- ----------
29 8
declare
empd emp2%rowtype;
begin
open empdetail;
DBMS_output.put_line('Emp Data:');
loop
DBMS_output.put_line('Eno:'||empd.eid);
DBMS_output.put_line('Name'||empd.ename);
DBMS_output.put_line('Salary'||empd.salary);
end loop;
close empdetail;
end;
/
output:
Emp Data:
Eno:1
NameMohit
Salary20000
Eno:2
Namesumit
Salary20000
Eno:3
Namerohan
Salary20000
Eno:4
Namemohan
Salary20000
Eno:5
Namekhushi
Salary12000
Eno:6
Namesoham
Salary14000
Eno:7
Namerahul
Salary24000
is
empd emp2%rowtype;
begin
DBMS_output.put_line('Emp Data:');
loop
DBMS_output.put_line('Eno:'||empd.eid);
DBMS_output.put_line('Name'||empd.ename);
DBMS_output.put_line('Salary'||empd.salary);
end loop;
output:
Emp Data:
Eno:1
NameMohit
Salary20000
is
begin
DBMS_output.put_line("Addition:"||no1+no2);
end;
is
begin
DBMS_output.put_line("Welcome:"||pname);
end;
is
begin
n3 :=no1+no2;
return n3;
end;