0% found this document useful (0 votes)
9 views4 pages

Dbnotes

The document contains a series of SQL commands for managing a database, including creating tables, inserting data, and performing various queries. It demonstrates operations such as creating employee and department tables, inserting records, updating data, and using joins and aggregations. Additionally, it includes commands for creating indexes and managing user permissions.

Uploaded by

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

Dbnotes

The document contains a series of SQL commands for managing a database, including creating tables, inserting data, and performing various queries. It demonstrates operations such as creating employee and department tables, inserting records, updating data, and using joins and aggregations. Additionally, it includes commands for creating indexes and managing user permissions.

Uploaded by

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

http://127.0.0.

1:9500/apex
sudo service oracle-xe start

select * from tab;


create table wiproemployee(id number primary key, name varchar(10), email
varchar(20));
desc wiproemployee;
insert into wiproemployee values(1,'user1','[email protected]');
select * from wiproemployee;

insert into wiproemployee(id) values(2);

insert into wiproemployee(id,name) values(3,'user1');

insert into wiproemployee(id,email) values(4,'[email protected]');

insert into wiproemployee values(5,'user5',null);

create table wemp as select * from wiproemployee;

desc wemp;

select * from wemp;

alter table wemp1 modify sal number(10);


alter table wemp1 add dept number(2);
alter table wemp1 modify dept number(5);
alter table wemp1 rename column dept to department;

alter table wemp1 add (city varchar(20), state varchar(20));


desc wemp1;

alter table wemp1 drop column state;

# DML
desc wemp1;
insert into wemp1
values(104,'user104','[email protected]',9999999999,7777,10,'HYD');
update wemp1 set department=20 where id=103;
update wemp1 set department=25,city='Chennai' where id=103;
update wemp1 set department=30,city='Mumbai' where id<=102;
insert into wemp1
values(105,'user104','[email protected]',3999999999,7777,10,'HYD');

insert into wemp1


values(106,'user104','[email protected]',9299999999,7777,10,'HYD');

delete from wemp1 where id=102 or city='Mumbai'


delete from wemp1 where not id=102 or id=103;
delete from wemp1 where id not in (104,105)
select * from wemp1;

create table student (id number primary key,name varchar(10), marks number check
(marks<100));

insert into student values(1,'s123',93);

create table dept (did number primary key,dname varchar(10));


insert into dept values(10,'IT');
insert into dept values(20,'INFRA');
insert into dept values(30,'ADMIN');
select * from dept;

create table empw(eid number primary key,name varchar(20),did references


dept(did));
insert into empw values(101,'ram',30);
insert into empw values(102,'raj',20);
insert into empw values(103,'kiran',10);
insert into empw values(104,'sam',30);
insert into empw values(105,'bindu',30);
insert into empw values(106,'ramarao',10);
insert into empw values(107,'sriram',20);
select * from empw;

select e.eid,e.name,d.did,d.dname from empw e,dept d where e.did=d.did;

#INDEX

select * from tab;


select * from wemp1;
select * from wemp1 where name='user104';
select * from wemp1 where id=106;
create index nameindex on wemp1(name);
create index i1 on wemp1(email);
select * from wemp1 where email=''
drop index i1;

CREATE TABLE Car


(
Pk_Car_Id number PRIMARY KEY,
Brand VARCHAR(100),
Model VARCHAR(100)
);

desc car;

CREATE TABLE Engineer


( Pk_Engineer_Id number PRIMARY KEY,
FullName VARCHAR(100),
MobileNo VARCHAR(11),
Fk_Car_Id number REFERENCES Car(Pk_Car_Id)
);

desc Engineer;
grant insert/delete/update/select to rpsuser1 on emp;

revoke all from rpsuser1 on emp;


select * from wemp1;
select id,name,city from wemp1;
select id,name,sal from wemp1;
select id,name,sal+500,sal*100 from wemp1;
select name, lower(name),upper(name),length(name) from wemp1;
select * from wemp1 where not id<=104;
select * from wemp1 where not id=104 or id=106;
select * from wemp1 where id not in(103,106);
select * from wemp1;
select * from dept;
select * from dept where dname not like 'I%';
select * from dept where did between 10 and 30;
select * from wemp1;
insert into wemp1 values(107,'ram','[email protected]','9898989898',9999,25,'Chennai');
insert into wemp1 values(108,'ram','[email protected]','9893989898',9999,25,'Pune');
insert into wemp1 values(109,'raj','[email protected]','8898989898',9999,25,'Chennai');
select sum(sal) from wemp1;
select department,sum(sal) from wemp1 group by department;
select city,avg(sal) from wemp1 group by city;

select avg(sal) from wemp1;


select max(sal) from wemp1;
select city,max(sal) from wemp1 group by city;
select min(sal) from wemp1;
select count(sal) from wemp1;
select city,count(sal) from wemp1 group by city;

select name,email, case when department=25 then 'T3' when department =10 then'T4'
else 'TT'
end as EmployeeBand from wemp1 ;

select current_date from dual;


select extract ( day from current_date) from dual;

create table coursew1(cid number primary key, cname varchar(10),duration


number(2));

create table studentw1( sid number primary key,sname varchar(20),dob date, cid
number references coursew1(cid));

insert into coursew1 values(1,'java',3);


insert into coursew1 values(2,'oracle',5);
insert into coursew1 values(3,'spring',4);

insert into coursew1 values(4,'html',3);


insert into coursew1 values(5,'rest',3);
select * from coursew1;
insert into studentw1 values(101,'ram','09-JAN-80',2);
insert into studentw1 values(102,'kiran','09-JAN-80',1);
insert into studentw1 values(103,'raj','09-JAN-80',3);
insert into studentw1 values(104,'ram','09-JAN-80',null);
insert into studentw1 values(105,'ram','09-JAN-80',null);
insert into studentw1 values(106,'ram','09-JAN-80',null);
select * from studentw1;

select s.sid,s.sname,s.dob,c.cid,c.cname,c.duration from studentw1 s inner join


coursew1 c on s.cid=c.cid;
select s.sid,s.sname,s.dob,c.cid,c.cname,c.duration from studentw1 s left outer
join coursew1 c on s.cid=c.cid;
select s.sid,s.sname,s.dob,c.cid,c.cname,c.duration from studentw1 s right outer
join coursew1 c on s.cid=c.cid;
select s.sid,s.sname,s.dob,c.cid,c.cname,c.duration from studentw1 s full outer
join coursew1 c on s.cid=c.cid;
select s.sid,s.sname,s.dob,c.cid,c.cname,c.duration from studentw1 s, coursew1 c;

select rownum,sid,sname from studentw1;


select * from employeew1;
select * from wemp1;

select department,sum(sal) from wemp1 group by department ;

select department,sum(sal) from wemp1 group by department having department=40;

select * from wemp1 order by city desc ;

select * from studentw1;


create table studentw2 as select * from studentw1;
select * from studentw2;
update studentw2 set sname='arun' where sid=104;
update studentw2 set sname='bindu' where sid=105;
update studentw2 set sname='chandu' where sid=106;
#SET
select * from studentw1 union select * from studentw2;
select * from studentw1 union all select * from studentw2;

select * from studentw1 intersect select * from studentw2;

select * from studentw1 minus select * from studentw2;


select * from studentw2 minus select * from studentw1;

create table empself(eid number primary key, name varchar(10),mid number);

insert into empself values (1,'ram',2);

insert into empself values(2,'ravi',1);


insert into empself values(3,'kiran',1);
insert into empself values(4,'akash',2);

insert into empself values(5,'raghav',1);

insert into empself values(6,'mahender',2);

select * from empself;

select e.eid ManagerID ,e.name Manager ,m.name EmployeeNAme from empself e join
empself m on e.eid=m.mid;

You might also like