DBMS Lab File
DBMS Lab File
1. Create a table in SQL with table name in departments and attributes are deptno, name,
location.
deptno number,
name varchar2(20),
location varchar2(20)
);
desc departments;
values(1,'CSE','Kalyani');
values(2,'CST','Kalyani');
values(3,'EE','Kolkata');
values(4,'ECE','Agarpara');
4. Write a SQL statement to display all the records in the departments table.
7. Write a SQL statement to add new column ‘no_of_emp’ in existing departments table.
eid number,
ename varchar2(20),
eaddress varchar2(20),
esal number
);
2. Insert values.
4. Select the name of the employee whose salary is greater 10000 and address in Kolkata.
5. Select the name of the employee whose salary is greater than 10000.
7. Find the address and name of the employee whose salary is greater than 30000.
11. Find the employee id and name ,salary is greater than 30000 and less than 50000.
1. Create a table student103 with attributes first name, middle name, last name, subject, age,
game and insert some values.
first_name varchar(20),
middle_name varchar(20),
last_name varchar(20),
subject varchar(20),
age number,
game varchar(20)
);
values('Ram','Kumar','Verma','Maths',12,'Football'),
('Shyam','Lal','Gupta','Physics',14,'Cricket'),
('Geeta','Devi','Patel','Chemistry',13,'Hockey'),
('Ramesh','Kumar','Singh','Maths',11,'Football'),
('Serama','Devi','Patel','English',29,'Cricket'),
('Sita','Devi','Sharma','CS',15,NULL),
('Aryan','Kumar','Mishra','English',27, NULL);
3. Find the first name and last name of the student whose subject is maths or physics.
4. Find the first name and age of the student whose age is between 10 to 15.
5. Find the first name, last name and game of the student whose game is football.
where game='Football';
6. Find the first name, last name and game of the student whose age is between 10 to 15 or
game is not football.
8. Find the first name and the last name of the student whose first name's second letter is -n.
9. Find the first name, last name and age of the student whose age is between 10 to 15 using
BETWEEN and AND keywords.
10. Find first name, last name of the student whose subject is maths or cs using IN keywords.
12. Find first, last name and subject of the student whose subject is neither maths nor physics
using NOT IN keywords.
1. Find the first name, last name, subject of the student in ascending order to their first
name.
order by first_name;
where subject='Maths';
7. Find the age of the students which is greater than 25 by subjects using group by and having
keyword.
first_name VARCHAR(50),
last_name VARCHAR(50),
address VARCHAR(100),
roll_no INT,
marks INT
);
2. Insert 5 rows.
9. Arrange the student name and roll no and marks according to their marks in descending
order.
SELECT first_name, last_name, roll_no, marks FROM student ORDER BY marks DESC;
EXPERIMENT 6
1. Create a table with roll number, name, address, phone and age given as below:
roll_no number,
name varchar(20),
address varchar(20),
phone number,
age number
);
values(1,'Harsh','Delhi',1234567890,18),
(2,'Pratik','Bihar',2134567890,19),
(3,'Riyanka','Siliguri',3124567890,20),
(4,'Deep','Ramnagar',4123567890,18),
(5,'Saptarhi','Kolkata',5123467890,19),
(6,'Dhanraj','Barabajar',6123457890,20),
(7,'Rohit','Balurghat',7123456890,18),
(8,'Niraj','Alipur',8123456790,19);
3. Create a table with student course id and roll number given as below:
COURSE_ID ROLL_NO
1 1
2 2
2 3
3 4
1 5
4 9
5 10
4 11
course_id number,
roll_no number
);
values(1,1),
(2,2),
(2,3),
(3,4),
(1,5),
(4,9),
(5,10),
(4,11);
5. Using a inner join clause, generate the table course id, name and age from the two tables.
from student2004
6. Generate using SQL left join having value name and course id.
from student2004
7. Generate using SQL right join having value name and course id.
from student2004
from student2004
emp_name VARCHAR(50),
emp_loc VARCHAR(50),
dept_name VARCHAR(50),
dept_no INT,
pro_name VARCHAR(50),
pro_no INT,
pro_loc VARCHAR(50)
);
INSERT INTO employee (emp_name, emp_loc, dept_name, dept_no, pro_name, pro_no, pro_loc)
5. Find the project name and project location for the project number is 100.
);
4. Update salary by 0.25 times for all customers whose age is greater than or equal to 25.
UPDATE customer
5. Delete records from customers whose age is greater than or equal to 35.
6. Select id and salary from customer table where age is same as customer with id 2.
SELECT id, salary FROM customer WHERE age = (SELECT age FROM customer WHERE id = 2);
7. Select id and salary from customer table where salary is equal to the minimum salary.
8. Select details from customers table where salary is equal to the average salary.