0% found this document useful (0 votes)
5 views

query1 (2)

Uploaded by

worksoumya34
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

query1 (2)

Uploaded by

worksoumya34
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

SQL=Structured Query Language

create database CSClass12;


use CSClass12;
create table product
(
prodId char(15) primary key,
PName varchar(50) not null,
Price decimal(10,2),
stock integer
)
alter table product
add constraint pkProdid primary key(prodid)
char-255
varchar-65535
alter table product
add constraint chkStock check(stock>=5)
alter table product
add pdesc varchar(100) after pname
alter table product
drop column pdesc

alter table product


modify column pdesc varchar(200)
alter table product
drop primary key
select * from product;
insert into product
values('P0002','hard disk',null,800,10)
insert into product
values('P0003','hard disk','1 TB',4500,7),
('P0004','RAM',null,1200,null),
('P0005','SMPS',null,null,10)
update product
set pname='UPS',pdesc=null,price=1200,stock=5
where prodid='P0003'

update product
set stock=stock+5
where prodid='P0002'
update product
set price=price+(price*0.1)

delete from product where prodid='P0002'


truncate table product
drop table product cascade

create table sales


(
sid int not null,
sdate date default(curdate()),
prodid char(15),
qty int,
amount bigint
)
select * from sales;
delete from sales
truncate table sales
drop table sales cascade
insert into sales
values(6,default,'P0002',6,54778)
insert into sales
values(1,default,'P0002',6,54778)
insert into sales
values(3,'2024-02-20','P0002',2,54778)
alter table sales
add constraint pksid primary key(sid)
alter table sales
add constraint fkprodid foreign key(prodid) references product(prodid)
select abs(-30)
alter table sales
add constraint chkQty check(qty>=1)
show databases
alter table product
add Pdesc varchar(100) after pname
alter table product
add constraint chkStock check(stock>=5)
DDL=create,alter,drop
DML=select ,insert,delete,update,truncate
DQL=select
DCL=GRANT, REVOKE
TCL=COMMIT,ROLLBACK
select database();
create database bank;
use bank;
show tables
desc customer
select * from customer
select Custname,accno,balance,acctype from customer
select Custname,accno,balance,acctype from customer where accno='AC0005'
select Custname,accno,balance,acctype from customer where accno='AC0005'
select Custname,accno,balance,acctype from customer where balance<10000
select * from customer where acctype='saving' and balance<50000 and gender='f'
select * from customer where acctype='saving' or acctype='student'
select * from customer where acctype in('saving','student')
select * from customer where acctype not in('saving','student')
select * from customer where acctype <>'saving'
select * from customer where acctype !='saving'
select * from customer where balance>=10000 and balance<=20000
select * from customer where balance between 10000 and 20000
select * from customer where Accno='AC0009';
SELECT * FROM TRAN
insert into sales
values(111,curdate(),'P003',2,7834)
show tables;
describe customer;
desc customer;
use bank;
select * from customer where acctype is null;
select Accno,custname,gender,Acctype,balance from customer;
select * from customer where accno='AC0005';
select * from customer where acctype='saving';
select * from customer where acctype='saving' or acctype='student';
select * from customer where acctype in('saving','student');
select * from customer where acctype not in('saving','student');
select * from customer where balance>=50000;
select * from customer where balance>=10000 and balance<=20000;
select * from customer where balance between 10000 and 20000 and gender='f';
select * from customer order by custname asc
select * from customer order by custname
select * from customer order by balance desc
select * from customer where gender='f' order by custname
select * from customer order by balance desc
select * from customer order by acctype, balance desc
select * from customer where Custname like's%';
select * from customer where Custname like'%y';
select * from customer where Custname like'%ma%';
select * from customer where LastName like'%d_';
select * from customer where AccType is null;
select count(*) 'Total customer' from customer;
select count(Acctype) from customer;
select distinct AccType from customer
select count(distinct AccType) from customer
select * from vwCust50
select acctype,count(*) as 'Total
Customer',sum(balance),avg(balance),max(balance),min(balance) from customer
group by acctype
select custname,accno,balance,balance+2000 from customer
select pname,price,price+price*0.1 as 'New Price' from product
select custname,accno,balance,balance+(balance*0.1) as 'new balance' from customer
select sellingPrice-CostPrice as 'Profit' from product
select deptName,count(*),avg(sal) from Emp group by deptName
select count(*),sum(balance),avg(balance),min(balance),max(balance) from customer
create view vwCust10
as
select acctype,count(*),sum(balance) from customer
group by Acctype
having sum(balance)>=50000
order by sum(balance) desc

select * from customer,tran


select * from customer join tran
select * from tran
create view vwCustTran
as
select AccType,count(*),sum(amount)
from customer inner join tran
on customer.accno=tran.accno
group by AccType
select * from vwCustTran
select Custname,acctype,balance,TranType,amount
from customer,tran
where customer.accno=tran.accno
select Custname,acctype,balance,TranType,amount
from customer join tran
on customer.accno=tran.accno
select c.accno,Custname,acctype,balance,TranType,amount
from customer c join tran t
on c.accno=t.accno
use bank;
select acctype,count(*),sum(balance) from customer group by acctype
having sum(balance)>=50000
select * from customer where acctype in('saving','student');
select Custname,acctype,balance,TranType,amount
from customer c join tran t
on c.accno=t.accno
select count(*) from customer cross join tran
select c.Accno,Custname,acctype,balance,TranType,amount
from customer c left outer join tran t
on c.accno=t.accno
create database bhavans9
use bhavans9
select database()
DDL=create,alter,drop
DQL
DML=select,insert,update,delete,truncate
DCL=grant,revoke
TCL=commit,rollback,savepoint
TCL

select TranType, count(*),sum(balance),sum(amount)


from customer c join tran t
on c.accno=t.accno
group by TranType

create table Product2


(
Prod_Id char(10) not null,
PName char(50) not null,
PDesc varchar(100),
Price integer(3) check(price>=100),
Stock bigint check(stock>=5),
pLDate date default(curdate())
);
insert into product2
values('P002','Hard Disk',null,350,20,'2023-12-09');
select * from product2;
update product2
set stock=stock-5
where prod_id='P002'
delete from product2 where prod_id='P002'
truncate table product2
drop table product2
desc Product2
use bank
select curdate() from dual;
select 3.14*5.4*5.4 as 'Area of circle' from dual
alter table product
add pdesc varchar(20);
alter table product
drop column pdesc;
alter table product1
add constraint pkProdid primary key(Prod_id);
alter table sales
add constraint fkPid foreign key(pid) references product(ProdID) on delete cascade
alter table product
modify column pdesc varchar(200) not null
alter table product1
add constraint chkStock check(Stock>=5)

drop table product cascade


select * from customer
delete from customer where accno='Ac0004'
truncate table customer
alter table product
add primary key(Prod_Id);

alter table product


add Supplier varchar(30);
select curdate();
desc Product1;
select * from product;
alter table product
add pdesc varchar(100) not null;
alter table product
modify column pdesc varchar(200) not null;
alter table product
drop column pdesc;
alter table product
drop primary key;
alter table product
drop check chkprice;
desc product;
select * from product1;
insert into product1(pname,price)
values('P0003','RAM',' 4 gb RAM',1200,2,null,'2023-11-25'),
('P002','RAM',null,1200,default,'dsf'),
('P002','RAM',null,1200,'2023-06-22','dsf');
truncate table product
drop table product cascade
alter table product
add pdesc varchar(100)
use bank
select * from customer where acctype !='saving';
update Product1
set pname='hard disk',pdesc=null,price=5000
where Prod_Id='P0002';

update Product1
set Price=Price+(Price*0.1);

delete from product


where Prod_Id='P002';

truncate table product


drop table product cascade
show tables;
show databases;
create database DAV3
use bank;

create table student


(
Std_Id char(10) not null,
StdName varchar(50) not null,
Age int,
AdmnDate date,
Course char(20)
)
alter table student
add constraint pkStdId primary key(Std_Id)
desc student
select * from customer where balance between 10000 and 20000
insert into student
values(3,'Shristi',null,'XI',default,20,null)

delete from student where std_id='S0002'

truncate table student


drop table student

update Student
set Course='IT',
where Std_id='S0001'

select * from student

CREATE database Pravas


use Pravas
create table product
(
ProdId char(10) primary key,
PName varchar(100),
Price int(5),
PLDate date,
Stock int
)
create table sales
(
sid int primary key,
sdate date default(curdate()),
pid char(10) ,
qty int,
amount bigint
);

select * from Product


insert into Product
values('P003','RAM',1200,default,null)
show databases
use bank;
select database();
show tables;
desc customer
select * from customer where accno='Ac0005';
select balance,custName,aod as 'Account Open Date',gender,Acctype from customer;
select custname,gender,Acctype,balance from customer where gender='f';
select custname,gender,Acctype,balance from customer where gender='f' and
acctype='saving';
select custname,gender,Acctype,balance from customer where acctype='saving'
select custname,gender,Acctype,balance from customer where acctype='saving' or
acctype='student';
select custname,gender,Acctype,balance from customer where acctype not
in('saving','student');
select * from customer where balance>10000
select * from customer where balance>=10000 and balance<=20000
select * from customer where balance between 10000 and 20000
select * from customer where custname like 's%'
select * from customer where custname like '%y'
select * from customer where custname like '%ma%'
select * from customer where custname like '_o%'
select * from customer where custname like '%t_'
select * from customer where LName not like 'd__'
select * from customer where acctype is null
select count(*) from customer
select count(acctype) from customer
select distinct acctype from customer
select count(distinct acctype) from customer
select count(*),sum(balance) ,avg(balance),min(balance) from customer
select * from customer where gender='f' order by CustName
select * from customer order by CustName asc
select * from customer order by balance desc
select * from customer order by acctype,balance desc
use bank
select sum(balance),count(*) from customer
select * from customer where Accno='AC0005'
insert into customer
values('C0001','AC0001','sanjib maji',,'2010-07-
20',default,20,25000,'durgachak,haldia','M','BPS894')

update customer
set balance=balance+2000
where AccNo='AC0005'
use bank;
show tables;
update customer
set gender='M'
where AccNo='AC0005'

update product
set price=price+(price*.1)

delete from customer where AccNo='AC0012'


truncate table product
drop table product
select * from customer
select * from vwCust5
create view vwCust5
as
select acctype, count(*),avg(balance) from customer
group by acctype
having avg(balance)>=50000
order by avg(balance)
select count(distinct Acctype) from customer
select count(*) from customer
select count(Acctype) from customer
use bank
select * from customer where acctype is null;

select * from customer order by balance desc


select * from customer order by Acctype asc, balance desc
select count(*),sum(balance) from customer
create view vwCustGP
as
select Acctype, count(*),sum(balance) as 'total' from customer
group by Acctype
having sum(balance)>=50000
select * from vwCustGP
order by sum(balance) desc
select * from vwCust1

select * from customer

insert into customer(custName,balance,custid,accno,pan)


values('akash',445434,'C0040','AC0040','u898u')

select * from Tran


select * from customer
select * from customer join tran
select * from vwCustomer
create view vwCustomer
as
select * from customer where accno='AC0003'
select * from customer where balance>=50000
select * from customer where acctype='saving'
select custname,AccType,balance,TranType,amount from customer join tran on
customer.AccNo=tran.AccNo
select custname,AccType,balance,TranType,amount from customer , tran where
customer.AccNo=tran.AccNo
select customer.accno,custname,AccType,balance,TranType,amount from
customer , tran where customer.AccNo=tran.AccNo and acctype='saving'
select custname,AccType,balance,TranType,amount from
customer join tran on customer.AccNo=tran.AccNo
where acctype='saving'

select tranType,count(*),sum(amount),avg(balance) from customer c join tran t on


c.AccNo=t.AccNo
group by trantype
create database bank;
use bank;
create table customer
(custID char(16) unique ,
AccNo varchar(20) primary key ,
CustName varchar(100),
AccType varchar(20),
AOD date default (curdate()),
Age int check(age>=18),
balance bigint check(balance>=3000),
Address varchar(100),
Gender char(20),
country char(15) default('india'),
PAN char(15) unique
);
select * from customer
use csclass12
desc customer;
data integrity:
entity-pk constraint

referential-fk
domain-check
user-defined-default
create database BiMi
use bimi;
create table product
(
prod_id char(10) primary key,
pname varchar(50) not null,
price integer,
stock int(5)
);
create table sales1
(
salesId int not null,
sdate date default(curdate()),
pid char(10),
qty int,
amount bigint
);
drop table sales1
alter table sales
add primary key(salesid);
use bank
select * from customer where custname like '%ma%'
select sum(balance),count(*),avg(balance),max(balance),min(balance) from customer
alter table sales
add foreign key(pid) references product(prod_id);

alter table sales


add pdesc varchar(100);

alter table sales


modify column pdesc varchar(200);

alter table sales


drop column pdesc;
desc sales;
alter table sales
add check(qty>=1)

select curdate()
select distinct acctype from customer
create database IOC;
use IOC;
create table Empl
(
Emp_No char(15) primary key,
EName varchar(30),
Job varchar(50),
HireDate date,
Salary bigint,
DeptId int
);
select * from empl
insert into empl
values('E009','sucharita mishra','hd','2019-05-10',66804,29);

You might also like