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

DBMS 5-11

The document outlines a series of SQL experiments involving the creation and manipulation of student, employee, and customer tables. It includes commands for creating tables, inserting data, and performing various SQL queries such as counting, finding maximum and minimum values, and joining tables. Each experiment demonstrates different SQL functionalities and operations on the created tables.

Uploaded by

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

DBMS 5-11

The document outlines a series of SQL experiments involving the creation and manipulation of student, employee, and customer tables. It includes commands for creating tables, inserting data, and performing various SQL queries such as counting, finding maximum and minimum values, and joining tables. Each experiment demonstrates different SQL functionalities and operations on the created tables.

Uploaded by

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

EXPERIMENT 5

1. Create a student table with attributes, first name, last name, address, roll no,

marks.

Ans: CREATE TABLE student (

first_name VARCHAR(50),

last_name VARCHAR(50),

address VARCHAR(100),

roll_no INT,

marks INT

);

2. Insert 5 rows.

Ans: INSERT INTO student (first_name, last_name, address, roll_no,

marks)VALUES (‘Alice’, ‘Johnson’, ‘123 Main St’, 1, 85),

(‘Bob’, ‘Smith’, ‘456 Oak St’, 2, 78),


(‘Charlie’, ‘Brown’, ‘789 Elm St’, 3, 92),

(‘David’, ‘Lee’, ‘101 Pine St’, 4, 65),

(‘Emily’, ‘Davis’, ‘222 Cedar St’, 5, 88);

3. Find the total number of students.

Ans: SELECT COUNT(*) AS total_students FROM student;


4. Find the maximum marks of the students

Ans: SELECT MAX(marks) AS max_marks FROM

student;

5. Find minimum marks obtained by the students

Ans: SELECT MIN(marks) AS min_marks FROM student;

6. Find the average marks of the students.

Ans: SELECT AVG(marks) AS avg_marks FROM

student;

7. Find total of the marks obtained by all student.

SELECT SUM(marks) AS total_marks FROM student;

8. List the students according to their marks in ascending order.

SELECT * FROM student ORDER BY marks ASC;

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 NAME ADDRESS PHONE AGE


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

create table student2004(

roll_no number,

name varchar(20),

address varchar(20),

phone number,

age number

);

2. Insert 8 rows as per the above data.

insert into student2004(roll_no,name,address,phone,age)

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

create table studentcourse2004 (

course_id number,

roll_no number

);

4. Insert 8 rows as per the above data.

insert into studentcourse2004(course_id,roll_no)

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.

select studentcourse2004.course_id, student2004.name, student2004.age

from student2004

inner join studentcourse2004 on student2004.roll_no = studentcourse2004.roll_no;

6. Generate using SQL left join having value name and course id.

select student2004.name, studentcourse2004.course_id

from student2004

left join studentcourse2004 on studentcourse2004.roll_no = student2004.roll_no;

7. Generate using SQL right join having value name and course id.

select student2004.name, studentcourse2004.course_id

from student2004

right join studentcourse2004 on studentcourse2004.roll_no = student2004.roll_no;


8. Generate the full join with name and course id.

select student2004.name, studentcourse2004.course_id

from student2004

full join studentcourse2004 on studentcourse2004.roll_no = student2004.roll_no;


EXPERIMENT 7
1. Create a table with employee having its employee name, employee location, employee
department name, department number, project name, project number, project location.

CREATE TABLE employee (

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)
);

2. Insert six rows.

INSERT INTO employee (emp_name, emp_loc, dept_name, dept_no, pro_name, pro_no, pro_loc)

VALUES ('Alice', 'Kolkata', 'HR', 1, 'Project A', 100, 'Mumbai'),

('Bob', 'Mumbai', 'IT', 2, 'Project B', 200, 'Delhi'),

('Charlie', 'Delhi', 'Finance', 3, 'Project C', 300, 'Chennai'),

('David', 'Chennai', 'Marketing', 4, 'Project D', 400, 'Kolkata'),

('Emily', 'Kolkata', 'HR', 1, 'Project E', 500, 'Mumbai'),

('Frank', 'Bangalore', 'Operations', 5, 'Project F', 600, 'Bangalore');

3. Find the 1st name of the employee who belongs to Kolkata.

SELECT emp_name FROM employee WHERE emp_loc = 'Kolkata' LIMIT 1;


4. Find the department name whose location is Mumbai.

SELECT dept_name FROM employee

WHERE pro_loc = 'Mumbai' LIMIT 1;

5. Find the project name and project location for the project number is 100.

SELECT pro_name, pro_loc FROM employee

WHERE pro_no = 100;

6. Find the project number which is executed by department number is 5.

SELECT pro_no FROM employee WHERE dept_no = 5;


EXPERIMENT 8
1. Create a table named customer with id, age, address, and salary. Make id as primary key
and make every other field not null.

CREATE TABLE customer (

id INT PRIMARY KEY,

age INT NOT NULL,

address VARCHAR(100) NOT NULL,

salary INT NOT NULL

);

2. Insert 10 rows with salary ranging from 50000 to 75000.

INSERT INTO customer (id, age, address, salary)

VALUES (1, 20, 'Kolkata', 55000),

(2, 25, 'Delhi', 60000),

(3, 30, 'Mumbai', 65000),

(4, 35, 'Chennai', 70000),

(5, 40, 'Bangalore', 75000),

(6, 22, 'Hyderabad', 52000),

(7, 28, 'Pune', 58000),

(8, 32, 'Ahmedabad', 62000),

(9, 38, 'Jaipur', 68000),

(10, 42, 'Lucknow', 72000);


3. Find all the customers whose salary is greater than 55000.

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.

UPDATE customer

SET salary = salary + (salary * 0.25)

WHERE age >= 25;

SELECT * FROM customer;

5. Delete records from customers whose age is greater than or equal to 35.

DELETE FROM customer WHERE age >= 35;

SELECT * FROM customer;

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.

SELECT id, salary FROM customer

WHERE salary = (SELECT MIN(salary) FROM customer);

8. Select details from customers table where salary is equal to the average salary.

SELECT * FROM customer

WHERE salary = (SELECT AVG(salary) FROM customer);

9. Select details of customers where salary is maximum.

SELECT * FROM customer

WHERE salary = (SELECT MAX(salary) FROM customer);


EXPERIMENT 9

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);

You might also like