Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
3 views

SQL PROGRAM 2

The document outlines a program to create a student database with a table for student records, including fields for ID, name, and marks in six subjects. It details steps for inserting records, altering the table to calculate total marks and percentage, determining pass/fail results, and retrieving various queries from the table. The program includes SQL commands for each operation, ensuring a structured approach to managing student data.

Uploaded by

preethid222007
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

SQL PROGRAM 2

The document outlines a program to create a student database with a table for student records, including fields for ID, name, and marks in six subjects. It details steps for inserting records, altering the table to calculate total marks and percentage, determining pass/fail results, and retrieving various queries from the table. The program includes SQL commands for each operation, ensuring a structured approach to managing student data.

Uploaded by

preethid222007
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

PROGRAM 2:

Create a student database and compute the results.

Create a table for class of students with the following fields.

Field Name Type

ID_NO NUMBER(4)

S_NAME VARCHAR2(15)

SUB1 NUMBER(3)

SUB2 NUMBER(3)

SUB3 NUMBER(3)

SUB4 NUMBER(3)

SUB5 NUMBER(3)

SUB6 NUMBER(3)

1. Add records into the table for 10 students for Student ID, Student Name and marks in 6 subjects using
INSERT command.

2. Display the description of the fields in the table using DESC command.

3. Alter the table and calculate TOTAL and PERC_MARKS.

4. Compute the RESULT as “PASSP or “FAIL” by checking if the student has scored more than 35 marks in
each subject.

5. List the contents of the table.

6. Retrieve all the records of the table.

7. Retrieve only ID_NO and S_NAME of all the students.

8. List the students who have result as “PASS”.

9. List the students who have result as “FAIL”.

10. Sort the table according to the order of ID_NO.


Solution:
First we have to create the table CLASS using CREATE TABLE command.

CREATE TABLE CLASS(ID_NO NUMBER(4), S_NAME VARCHAR2(15), SUB1 NUMBER(3),SUB2


NUMBER(3),SUB3 NUMBER(3),SUB4 NUMBER(3),SUB5 NUMBER(3),SUB6 NUMBER(3));

1. Add records into the table for 5 students for Student ID, Student Name and marks in 6 subjects using
INSERT command.

INSERT INTO CLASS VALUES (1401, 'PAWAN', 56, 36, 56, 78, 44, 67);

INSERT INTO CLASS VALUES (1411, 'RAJESH', 100,100,96,100,100,100);

INSERT INTO CLASS VALUES (1412, 'KARAN', 60,30,45,45,36,49);

INSERT INTO CLASS VALUES (1403, 'SACHIN', 56,60,72,57,78,67);

INSERT INTO CLASS VALUES (1410, 'PRAKASH', 96,99,97,90,78,100);

2. Display the description of the fields in the table using DESC command.

DESC CLASS;

3. Alter the table and calculate TOTAL and PERC_MARKS.

ALTER TABLE CLASS ADD(TOTAL NUMBER(3),PERC_MARKS NUMBER(6,2),RESULT VARCHAR2(10));

UPDATE CLASS SET TOTAL=SUB1+SUB2+SUB3+SUB4+SUB5+SUB6;

UPDATE CLASS SET PERC_MARKS=TOTAL/6;

4. Compute the RESULT as “PASS”or “FAIL” by checking if the student has scored more than 35 marks in
each subject.

UPDATE CLASS SET RESULT='PASS' WHERE (SUB1>=35 AND SUB2>=35 AND SUB3>=35 AND SUB4>=35
AND SUB5>=35 AND SUB6>=35);

UPDATE CLASS SET RESULT='FAIL' WHERE (SUB1<35 OR SUB2<35 OR SUB3<35 OR SUB4<35 OR


SUB5<35 OR SUB6<35);

5. Retrieve all the records of the table.

SELECT * FROM CLASS;

6. Retrieve only ID_NO and S_NAME of all the students

SELECT ID_NO,S_NAME FROM CLASS;

7. List the students who have result as “PASS”.

SELECT * FROM CLASS WHERE RESULT='PASS';


8. List the students who have result as “FAIL”

SELECT * FROM CLASS WHERE RESULT='FAIL';

9. Sort the table according to the order of ID_NO.

SELECT * FROM CLASS ORDER BY ID_NO;

You might also like