0% found this document useful (0 votes)
5 views6 pages

SQL assignment

The document outlines a SQL assignment involving the creation and manipulation of a 'student' table with various attributes including id, name, dept, year, age, semester, passing year, marks, and result. It includes instructions for creating the table, inserting data, updating records, and retrieving specific information based on conditions. The assignment also covers altering the table structure and managing student results based on their marks.

Uploaded by

suranjan.jana1
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 views6 pages

SQL assignment

The document outlines a SQL assignment involving the creation and manipulation of a 'student' table with various attributes including id, name, dept, year, age, semester, passing year, marks, and result. It includes instructions for creating the table, inserting data, updating records, and retrieving specific information based on conditions. The assignment also covers altering the table structure and managing student results based on their marks.

Uploaded by

suranjan.jana1
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/ 6

SQL assignment

1. create a relationship with the following attributes - id,


name, dept, year, age.
2. show the description of the table.
3. insert value in the table.
4. retrieve all the info stored in the table.
5. display student details where dept is cse .
6. display student ID and name where dept is ece .
7. update the age of the student whose ID is 4.
8. include an attribute semester in relation to the student .
9. retrieve all the info .
10. set semester as 6 for all the student
11. include an attribute passing year in relation student
12. rename the column year from the table
13. insert value in to the student keeping the new attribute
passing year blank
14. retrieve all the info
15. set semester as 7 where dept is IT
16. show the distinct dept from the relation student
17. list the student name where age is > 20 to 24
18. include a attribute marks in the relation whose marks is
less than 65, whose marks is greater than 65,whose marks
is greater than 75,whose marks is greater than 95
19. include new attribute result
20. insert values in to result column if the marks of the
student is above 60 else null
21. list all the info from the relation where the result is null
and update the value as not promoted
22. show the name and dept of student according to their
marks in ascending and descending order .
-- 1. Create a relationship (table) with given attributes
CREATE TABLE student (
id INT PRIMARY KEY,
name VARCHAR(50),
dept VARCHAR(10),
year INT,
age INT
);

-- 2. Show the description of the table


DESC student;

-- 3. Insert values into the table


INSERT INTO student (id, name, dept, year, age) VALUES
(1, 'Alice', 'CSE', 2, 20),
(2, 'Bob', 'ECE', 3, 21),
(3, 'Charlie', 'MECH', 4, 22),
(4, 'David', 'CSE', 1, 19),
(5, 'Eve', 'IT', 2, 23);

-- 4. Retrieve all the info stored in the table


SELECT * FROM student;

-- 5. Display student details where dept is CSE


SELECT * FROM student WHERE dept = 'CSE';

-- 6. Display student ID and name where dept is ECE


SELECT id, name FROM student WHERE dept = 'ECE';

-- 7. Update the age of the student whose ID is 4


UPDATE student SET age = 20 WHERE id = 4;

-- 8. Include an attribute semester in the relation


ALTER TABLE student ADD COLUMN semester INT;

-- 9. Retrieve all the info


SELECT * FROM student;

-- 10. Set semester as 6 for all students


UPDATE student SET semester = 6;

-- 11. Include an attribute passing year


ALTER TABLE student ADD COLUMN passing_year INT;

-- 12. Rename the column 'year' to 'admission_year'


ALTER TABLE student CHANGE year admission_year INT;

-- 13. Insert values keeping passing year blank


INSERT INTO student (id, name, dept, admission_year, age,
semester, passing_year) VALUES
(6, 'Frank', 'EEE', 3, 22, 6, NULL);

-- 14. Retrieve all the info


SELECT * FROM student;

-- 15. Set semester as 7 where dept is IT


UPDATE student SET semester = 7 WHERE dept = 'IT';

-- 16. Show distinct dept from the student table


SELECT DISTINCT dept FROM student;

-- 17. List student names where age is > 20 to 24


SELECT name FROM student WHERE age BETWEEN 20 AND
24;
-- 18. Include an attribute marks
ALTER TABLE student ADD COLUMN marks INT;

-- Update marks for students


UPDATE student SET marks = 60 WHERE id = 1;
UPDATE student SET marks = 70 WHERE id = 2;
UPDATE student SET marks = 80 WHERE id = 3;
UPDATE student SET marks = 95 WHERE id = 4;
UPDATE student SET marks = 50 WHERE id = 5;

-- 19. Include a new attribute result


ALTER TABLE student ADD COLUMN result VARCHAR(20);

-- 20. Insert values in the result column if marks > 60, else
NULL
UPDATE student SET result = 'Passed' WHERE marks > 60;
UPDATE student SET result = NULL WHERE marks <= 60;

-- 21. List all info where the result is NULL and update as 'Not
Promoted'
SELECT * FROM student WHERE result IS NULL;
UPDATE student SET result = 'Not Promoted' WHERE result IS
NULL;

-- 22. Show the name and dept of students according to


marks in ascending and descending order
SELECT name, dept FROM student ORDER BY marks ASC;
SELECT name, dept FROM student ORDER BY marks DESC;

You might also like