You are on page 1of 11

DBMS Assignment 1

Name - Panshul Saxena


Batch - 2CS10
Roll No - 102196006

Q1. Create table Student (Roll_number, Name, DOB, Gender, Class,


University, City, Marks).
create database students;
use students;
create table students(roll_number int(10),name varchar(20),date_of_birth date,gender
varchar(20),class varchar(20),University char(50),city varchar(30),marks int(10));

Q2. Insert 5 records in student table.


insert into students values ('1','Ayush','2000-04-04','male','cose','thapar
derabassi','Chandigharh','60');
insert into students values ('2','Binod','2000-05-02','male','cose','thapar derabassi ','Nagpur','80');
insert into students values ('3','Chitra','2001-10-08','female','coe',' thapar patiala ','Delhi','40');
insert into students values ('4','Dharam','2002-06-28','male','cose',' thapar patiala ','Patiala','55');
insert into students values ('5','Gaurav','2001-10-08','male','coe',' thapar patiala ','Noida','40');
insert into students values('6','Harsh','2000-01-15','male','coe','thapar patiala','Amritsar','30');
insert into students values('7','Nishu','2000-11-30','male','cose','thapar derabassi','Varanasi','86');
insert into students values('8','Priya','2000-04-18','female','cose','thapar
derabassi','Chandighar','75');
insert into students values('9','Rohan','2000-08-08','male','coe','thapar patiala','Jalandar','55');

Q3. Display the information of all the students.


select * from students;
Q4. Display the detail structure of student table.
desc students;

Q5. Display roll_number, Name and Class information of ‘Patiala’


students.
SELECT roll_number, name, class FROM Students where university = 'thapar patiala';

Q6. Display information on ascending order of marks


SELECT * FROM students ORDER BY marks ASC;
Q7. Change the marks of roll_number 5 to 89.
update students set marks = 89 where roll_number = 5;

Q8. Change the name and city of roll_number 9.


update students set name = 'Sanam' , city = 'Patiala' where roll_number = 9;
Q9. Delete the information of ‘Amritsar’ city records.
DELETE FROM students WHERE city = 'Amritsar';

Q10. Delete the records of student where marks<30.


DELETE FROM students WHERE marks <= 30 ;
DBMS Assignment 2
1. Create table emp which has the following attributes
(employee table) (empno, ename, job, sal, deptno) 
create database EMP;
use EMP;
CREATE TABLE employee (
empno int(3),
ename varchar(20) ,
job varchar(50),
deptno int(10),
sal int(10),
commission int(3)
);
2. Insert appropriate records in above tables. 
INSERT INTO employee VALUES (101, 'aarya', 'Manager', 10 , 3275 , NULL);
INSERT INTO employee VALUES (201, 'Baman', 'Assistant Manager', 15 , 2467 , NULL);
INSERT INTO employee VALUES (301, 'RitiC', 'Treasurer', 25 , 734 , 0.7);
INSERT INTO employee VALUES (401, 'Abhay', 'Clerks', 10 , 8862 , 0.9);
INSERT INTO employee VALUES (501, 'Chitra', 'Salesperson', 8 , 575 , 1.4);
INSERT INTO employee VALUES (601, 'Abbas', 'Clerks', 6 , 2022 , 7);

3. Get employee no and employee name who works in


dept no 10 
SELECT empno,ename FROM employee WHERE deptno=10;
4. Display the employee names of those clerks whose
salary >2000
SELECT ename FROM employee where sal>2000;

5. Display name and sal of Salesperson & Clerks  


SELECT ename,sal FROM employee WHERE job='Salesperson' or job='Clerks';
6. Display all details of employees whose salary between 2000 and
3000 
SELECT * FROM employee WHERE sal>1999 and sal<3001 ;

7. Display all details of employees whose dept no is 10, 20, or 30


SELECT * FROM employee WHERE deptno=10 or deptno=20 or deptno=30 ;

8. Display name of those employees whose commission is NULL


SELECT ename FROM employee WHERE commission IS NULL;

9. Display dept no & salary in ascending order of dept no and with in


each dept no  salary should be in descending order  
SELECT deptno,sal FROM employee ORDER BY deptno,sal DESC;
10. Display name of employees that starts with ‘C’ 
SELECT ename FROM employee WHERE ename LIKE 'c%';

11. Display name of employees that ends with with ‘C’


SELECT ename FROM employee WHERE ename LIKE '%C';

12. Display name of employees having two ‘a’ or ‘A’ chars in


the name
SELECT ename FROM employee WHERE ename LIKE 'aa%' or '%aa%' or '%aa' or 'AA%' or '%AA%' or
'%AA';

13. Display the name of the employees whose second char is


‘b’ or ‘B’
SELECT ename FROM employee WHERE ename LIKE '_b%' or '_B%';

  14. Display the name of the employees whose first or last


char is ‘a’ or ‘A’
SELECT ename FROM employee WHERE ename LIKE 'a%' or 'A%' or '%a' or '%A';
/*create table students(roll_number number(10),name varchar(20),date_of_birth date,gender
varchar(20),class varchar(20),University char(50),city varchar(30),marks number(10));
insert into students values (1,'Ayush','04-JAN-2000','male','cose','thapar derabassi','Chandigharh',60);
insert into students values (2,'Binod','02-FEB-2001','male','cose','thapar derabassi ','Nagpur',80);
insert into students values (3,'Chitra','08-MAR-2002','female','coe',' thapar patiala ','Delhi',40);
insert into students values (4,'Dharam','28-APR-1999','male','cose',' thapar patiala ','Patiala',55);
insert into students values (5,'Gaurav','08-MAY-1998','male','coe',' thapar patiala ','Noida',40);
insert into students values(6,'Harsh','15-JUN-2005','male','coe','thapar patiala','Amritsar',30);
insert into students values(7,'Nishu','30-JUL-2003','male','cose','thapar derabassi','Varanasi',86);
insert into students values(8,'Priya','18-DEC-2004','female','cose','thapar derabassi','Chandighar',75);
insert into students values(9,'Rohan','08-NOV-1998','male','coe','thapar patiala','Jalandar',55);
desc students;*/

select * from students;

/*create table students(roll_number number(10),name varchar(20),date_of_birth date,gender


varchar(20),class varchar(20),University char(50),city varchar(30),marks number(10));
insert into students values (1,'Ayush','04-JAN-2000','male','cose','thapar derabassi','Chandigharh',60);
insert into students values (2,'Binod','02-FEB-2001','male','cose','thapar derabassi ','Nagpur',80);
insert into students values (3,'Chitra','08-MAR-2002','female','coe',' thapar patiala ','Delhi',40);
insert into students values (4,'Dharam','28-APR-1999','male','cose',' thapar patiala ','Patiala',55);
insert into students values (5,'Gaurav','08-MAY-1998','male','coe',' thapar patiala ','Noida',40);
insert into students values(6,'Harsh','15-JUN-2005','male','coe','thapar patiala','Amritsar',30);
insert into students values(7,'Nishu','30-JUL-2003','male','cose','thapar derabassi','Varanasi',86);
insert into students values(8,'Priya','18-DEC-2004','female','cose','thapar derabassi','Chandighar',75);
insert into students values(9,'Rohan','08-NOV-1998','male','coe','thapar patiala','Jalandar',55);
desc students;*/

select name,roll_number,date_of_birth,marks,class,city,University,case gender when 'female' then


marks+10 else marks end "Rvised marks" from students;
--select * from students;
--select round(23.8349,1) from dual;

create table dept(deptno number primary key,dname varchar(50));

intsert into dept values(10,'aaa');


insert into dept values(20,'bbb');

create table emp(empno number not null primary key, ename


varchar(50) unique, job varchar(100), sal number not null, deptno
int, foreign key(deptno) references dept(deptno));
/*create table students(roll_number number(10),name varchar(20),date_of_birth date,gender
varchar(20),class varchar(20),University char(50),city varchar(30),marks number(10));
insert into students values (1,'Ayush','04-JAN-2000','male','cose','thapar derabassi','Chandigharh',60);
insert into students values (2,'Binod','02-FEB-2001','male','cose','thapar derabassi ','Nagpur',80);
insert into students values (3,'Chitra','08-MAR-2002','female','coe',' thapar patiala ','Delhi',40);
insert into students values (4,'Dharam','28-APR-1999','male','cose',' thapar patiala ','Patiala',55);
insert into students values (5,'Gaurav','08-MAY-1998','male','coe',' thapar patiala ','Noida',40);
insert into students values(6,'Harsh','15-JUN-2005','male','coe','thapar patiala','Amritsar',30);
insert into students values(7,'Nishu','30-JUL-2003','male','cose','thapar derabassi','Varanasi',86);
insert into students values(8,'Priya','18-DEC-2004','female','cose','thapar derabassi','Chandighar',75);
insert into students values(9,'Rohan','08-NOV-1998','male','coe','thapar patiala','Jalandar',55);
desc students;*/

--select sum(marks),avg(marks),min(marks),max(marks) from students;


select gender,sum(marks) from students group by gender;

You might also like