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

SQL Practical Code

The document outlines SQL commands for creating and manipulating various database tables, including 'product', 'student', 'exam', 'doctor', 'employee', 'division', 'member', 'salesman', and 'customer'. It includes commands for creating tables, inserting data, updating records, and querying information based on specific criteria. Additionally, it demonstrates the use of aggregate functions and joins to retrieve and analyze data from multiple tables.

Uploaded by

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

SQL Practical Code

The document outlines SQL commands for creating and manipulating various database tables, including 'product', 'student', 'exam', 'doctor', 'employee', 'division', 'member', 'salesman', and 'customer'. It includes commands for creating tables, inserting data, updating records, and querying information based on specific criteria. Additionally, it demonstrates the use of aggregate functions and joins to retrieve and analyze data from multiple tables.

Uploaded by

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

1. i.

create table product(PCode varchar(10) primary key,PName varchar(50),UPrice


int,Manufacturer varchar(30));

insert into product values('P01','Washing Powder',120,'Surf'),

-> ('P02','Tooth Paste',54,'Colgate'),

-> ('P03','Soap',25,'Lux'),

-> ('P04','Tooth Paste',65,'Pepsodant'),

-> ('P05','Soap',38,'Dove'),

-> ('P06','Shampoo',245,'Dove');

iii. select pname,uprice,pcode from product order by pname desc;

select pname,uprice,pcode from product order by uprice;

iv. alter table product add discount int;

v. update product set discount=uprice*10/100 where uprice>100;

update product set discount=0 where uprice<100;

vi. update product set uprice=uprice+uprice*12/100 where manufacturer='dove';

vii. select count(pname) as total_no_of_products_by_each_manufacturer,manufacturer from


product group by manufacturer;

2. a. create database streams_of_students;

d. update student set stcode='S03' WHERE NAME='JAY';

E. SELECT NAME FROM STUDENT WHERE NAME LIKE '%A' ORDER BY NAME;

F. select s.name from student s,stream st where st.stream in ('Science','Humanities') and


s.stcode=st.stcode order by s.name;

select s.name from student s,stream st where st.stream in ('Science','Humanities') and


s.stcode=st.stcode order by s.admno;

G. SELECT COUNT(S.NAME),ST.STREAM FROM STUDENT S,STREAM ST WHERE


S.STCODE=ST.STCODE GROUP BY ST.STREAM HAVING COUNT(S.NAME)>1;

H. SELECT NAME FROM STUDENT ORDER BY ADMNO DESC;


J. ALTER TABLE STREAM ADD TEACHERINCHARGE VARCHAR(30);

k. select st.teacherincharge,s.name from stream ST,student S where s.stcode=st.stcode;

3.

i. select * from exam where stream='humanities' order by percentage desc;

ii. select adno,sname,percentage,stream from exam where length(sname)<6;

III. ALTER TABLE ADD BUSFEES DECIMAL(8,2);

iV. update exam set percentage=percentage+percentage*2/100 where stream='humanities';

4.

i. SELECT NAME FROM EXAM WHERE DIVISION='FIRST' ORDER BY NAME;

II. SELECT NAME,SUBJECT,STIPEND AS ANNUALSTIPEND FROM EXAM;

III. SELECT COUNT(*) AS NO_OF_STUDENTS FROM EXAM WHERE SUBJECT='ACCOUNTS' OR


SUBJECT='INFORMATICS';

5.

I. SELECT * FROM DOCTOR WHERE EXPERIENCE>5 ORDER BY DNAME;

II. UPDATE DOCTOR SET SALARY=SALARY+SALARY*15/100 WHERE EXPERIENCE>8;

III. SELECT DNAME FROM DOCTOR WHERE DNAME LIKE '%H';

IV. SELECT DISTINCT(CITY) FROM DOCTOR;

V. SELECT DNAME FROM DOCTOR WHERE CITY='JAIPUR' OR CITY='TONK';

VI. ALTER TABLE DOCTOR ADD ADHARNO INT;

VII. SELECT * FROM DOCTOR ORDER BY SALARY DESC;

6.

I. SELECT E.EMPLOYEEID,E.NAME,E.JOBID,J.JOBTITLE FROM EMPLOYEE E,JOB J WHERE


E.JOBID=J.JOBID;

II. SELECT E.NAME,E.SALES,J.JOBTITLE FROM EMPLOYEE E,JOB J WHERE E.SALES>1300000 AND


E.JOBID=J.JOBID;

III. SELECT E.NAME,J.JOBTITLE FROM EMPLOYEE E,JOB J WHERE E.NAME LIKE '%SINGH%' AND
E.JOBID=J.JOBID;
IV. UPDATE EMPLOYEE SET JOBID=104 WHERE EMPLOYEEID='E4';

7. create table division(Divno int primary key,Divname varchar(30),Location varchar(20));

create table member(EmpId int primary key,Name varchar(30),Pay int,Divno int,foreign key(divno)
references division(divno) on delete cascade on update cascade);

i. select m.name,d.divname from member m,division d where d.divno=m.divno;


ii. select m.divno,d.divno from member m,division d where d.divno=m.divno;
iii. SELECT DISTINCT(M.DIVNO) FROM MEMBER M,DIVISION D WHERE D.DIVNO=M.DIVNO;
iv. select divno from member;
v. select divno from division;
vi. Select m.divno from member m,division d where m.divno=d.divno;

8. create table salesman(salesman_id int primary key,name varchar(30),city varchar(40),commission


int);

create table customer(customer_id int primary key,cust_name varchar(40),city varchar(40),grade


int,salesman_id int,foreign key(salesman_id) references salesman(salesman_id) on delete cascade on
update cascade);

insert into salesman values(1001,'Muktar','Chennai',20),

-> (1002,'Surya','Jammu',13),

-> (1003,'Karish','Chennai',21),

-> (1004,'Sunish','Delhi',10),

-> (1005,'Ajay','Jammu',15);

insert into customer values(10,'Mona','Jammu',200,1005),

-> (20,'Vijay','Delhi',150,1004),

-> (30,'April','Delhi',230,1004),

-> (40,'Misha','Chennai',120,1003),

-> (50,'Aarav','Chennai',210,1001);

i. select c.cust_name,s.name from salesman s,customer c where c.salesman_id=s.salesman_id and


s.city=’Chennai’ and c.city=’chennai’;

ii. select distinct(name),city from salesman;

iii. select s.name from salesman s,customer c where s.salesman_id=c.salesman_id and c.city!='Delhi' and
c.city!='Jammu';
iv. select s.name from salesman s,customer c where s.salesman_id=c.salesman_id and c.grade>=200;

v. select s.name from salesman s,customer c where s.salesman_id=c.salesman_id and c.grade=200 and
c.city='Jammu';

vi. select c.cust_name from customer c,salesman s where s.commission>=15 and


s.salesman_id=c.salesman_id;

You might also like