DBMS 5-11
DBMS 5-11
1. Create a student table with attributes, first name, last name, address, roll no,
marks.
first_name VARCHAR(50),
last_name VARCHAR(50),
address VARCHAR(100),
roll_no INT,
marks INT
);
2. Insert 5 rows.
student;
student;
9. Arrange the student name and roll no and marks according to their marks in descendingorder.
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 an 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.
1. Create a table named customer with id, age, address and salary. Make is as primary key and
make every other field not null.
Ans: CREATE TABLE customer (
id INT PRIMARY KEY,
age INT NOT NULL,
address VARCHAR(255) NOT NULL,
salary FLOAT NOT NULL
);
2. Insert 10 values with salary ranging from 50000 to 75000.
Ans: INSERT INTO customer (id, age, address, salary) VALUES
(1, 22, '100 Maple St, Springfield', 52000),
(2, 28, '123 Main St, Springfield', 60000),
(3, 34, '456 Elm St, Maplewood', 68000),
(4, 21, '789 Oak St, Fairview', 55000),
(5, 29, '321 Pine St, Centerville', 70000),
(6, 24, '654 Cedar Ave, Brookfield', 75000),
(7, 30, '987 Birch Rd, Sunnyvale', 62000),
(8, 27, '555 Walnut Ln, Roseville', 54000),
(9, 26, '222 Cherry Dr, Greenfield', 58000),
(10, 32, '333 Ash St, Riverdale', 50000);
3. Find the customer whose salary is greater than 55000.
Ans: SELECT * FROM customer WHERE salary > 55000;
4. Update salary by 0.25 times for all customers whose age is greater than or equal to 25.
Ans: UPDATE customer
SET salary = salary * 1.25
WHERE age >= 25;
5. Delete records from customer whose age is greater than or equal to 35.
Ans: DELETE FROM customer WHERE age >= 35;
6. Select id and salary from customer table where age is same as customer with id 2.
Ans: SELECT id, salary
FROM customer
WHERE age = (SELECT age FROM customer WHERE id = 2);
7. Select id and salary from customer table where alary is equal to the minimum salary.
Ans: SELECT id, salary
FROM customer
WHERE salary = (SELECT MIN(salary) FROM customer);
8. Select details from customer table where salary is equal to the average salary.
Ans: SELECT *
FROM customer
WHERE salary = (SELECT AVG(salary) FROM customer);
No records matched the average salary condition.
9. Select details of customers where salary is maximum.
Ans: SELECT *
FROM customer
WHERE salary = (SELECT MAX(salary) FROM customer);