DDL and DML Commands for Student Table in SQL Plus
a. Create the student table:
CREATE TABLE student (
name VARCHAR2(10),
rollno VARCHAR2(5)
);
b. Add branch column to the student table:
ALTER TABLE student ADD branch VARCHAR2(20);
c. Increase the size of rollno column from 5 to 10:
ALTER TABLE student MODIFY rollno VARCHAR2(10);
d. Add marks1, marks2, marks3, and dob columns to the student table:
ALTER TABLE student ADD (
marks1 NUMBER,
marks2 NUMBER,
marks3 NUMBER,
dob DATE
);
e. Insert at least 5 rows into the student table:
INSERT INTO student (name, rollno, branch, marks1, marks2, marks3, dob)
VALUES ('John', '101', 'CSE', 85, 90, 88, TO_DATE('1999-08-15', 'YYYY-MM-DD'));
INSERT INTO student (name, rollno, branch, marks1, marks2, marks3, dob)
VALUES ('Alice', '102', 'ECE', 70, 75, 80, TO_DATE('2000-03-22', 'YYYY-MM-DD'));
INSERT INTO student (name, rollno, branch, marks1, marks2, marks3, dob)
VALUES ('Bob', '103', 'CSE', 95, 92, 98, TO_DATE('1998-05-12', 'YYYY-MM-DD'));
INSERT INTO student (name, rollno, branch, marks1, marks2, marks3, dob)
VALUES ('Diana', '104', 'CSE', 60, 65, 70, TO_DATE('1999-10-10', 'YYYY-MM-DD'));
INSERT INTO student (name, rollno, branch, marks1, marks2, marks3, dob)
VALUES ('Eve', '105', 'ECE', 55, 58, 60, TO_DATE('2001-01-01', 'YYYY-MM-DD'));
f. Display name and rollno of all students:
SELECT name, rollno FROM student;
g. Add a total column to the student table:
ALTER TABLE student ADD total NUMBER;
h. Calculate the total of every student:
UPDATE student SET total = marks1 + marks2 + marks3;
i. Display the details of CSE students:
SELECT * FROM student WHERE branch = 'CSE';
j. Display the structure of the student table:
DESC student;
k. Display all rows and columns from the student table:
SELECT * FROM student;
l. Display the name and total obtained by every student:
SELECT name, total FROM student;
m. Display the details of students who got above 250 marks:
SELECT * FROM student WHERE total > 250;
n. Add an average column to the student table:
ALTER TABLE student ADD average NUMBER;
o. Find out the average marks for every student:
UPDATE student SET average = total / 3;
p. Display the details of students who got above 80 percent:
SELECT * FROM student WHERE average > 80;
q. Modify the branch values from CSE to ECE:
UPDATE student SET branch = 'ECE' WHERE branch = 'CSE';
r. Display the details of students whose dob is 12-05-1991:
SELECT * FROM student WHERE dob = TO_DATE('1991-05-12', 'YYYY-MM-DD');
s. Remove details of ECE students:
DELETE FROM student WHERE branch = 'ECE';
t. Remove the dob column from the student table:
ALTER TABLE student DROP COLUMN dob;
u. Remove all the records from the student table:
DELETE FROM student;