Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

create table customer

(
customer_id varchar2(10) primary key,
customer_name char(50) not null,
phn_no int unique,
country char(30) default 'India',
age int check(age>18),
product_id varchar2(50) references product(product_id)
);

insert into customer(customer_id,customer_name,phn_no,age,product_id) values


('C01','ABHI',548566565,22,'P01');
insert into customer(customer_id,customer_name,phn_no,country,age,product_id)
values ('C05','KURIPP',54666662,'UK',52,'P02');
desc product
select * from CUSTOMER
update product
set product_type='stationary'
where product_id='P01'
delete from customer where customer_id='C01'
commit;
rollback;
select country from customer where customer_name='HUHUBIE'
select * from product
select product_id,product_name, price*10 from product
select product_id, price as cost from product
select distinct product_id from product
select * from product order by price <--------------- ASC =ascending order by
default.............DESC<--------descending

create table Employeee


(
Empid int primary key,
Empname varchar(50),
Deptid int references Department(Deptid)
);
select * from Employeee
create table Department
(
Deptid int primary key,
Deptname varchar(50)
);

insert into Employeee(Empid,Empname) values (205, 'F');

QUERY FOR INNER JOIN( also called equi join if there is an equal to operator in the
command)
select * from Employeee inner join department on
Employeee.Deptid=Department.Deptid;

CROSS JOIN
select * from Employeee cross join Department;

NATURAL JOIN
select * from Employeee natural join Department;

LEFT OUTER JOIN


select * from Employeee left outer join Department on
Employeee.Deptid=Department.Deptid;
create table employeeU(
employee_id varchar2(50) primary key,
employee_name char(50) not null,
salary int,
dept varchar(20)
);
insert into employeeU(employee_id,employee_name,salary,dept) values ('E05',
'HIZAN',50000, 'FASHION');
select min(salary) from employee;
select max(salary) from employee;
select * from employee;
select avg(salary) from employee;
alter table employee
add dept varchar(20);
set employee_name='HUHUBIE' where employee_id='E05';
update employee
set dept='' where employee_id='E01';
update employee
set dept='ECE' where employee_id='E06';
select avg(salary), dept from employee group by dept
alter table employee drop constraint salary;
select count(distict salary) from employee;
desc employee
select max(salary),dept from employee group by dept having max(salary)>10000 order
by max(salary) DESC ;
select * from employee where salary between 20000 and 40000
ALTER TABLE EMPLOYEE MODIFY SALARY INT;
SELECT * from employee union
select * from employeeU
SELECT * from employee intersect
select * from employeeU

finds all values starting with '20'

select salary from employee where salary like '20%'

anything can be there before and after 000

select salary from employee where salary like '%000%'


select EMPLOYEE_NAME from employee where EMPLOYEE_NAME like '%H%' LIKE IS CASE
SENSITIVE
IN;ANY;ALL; AND SUBQUERIES

You might also like