You are on page 1of 10

STUDENT MARKLIST-1

AIM: Create the following table and insert records into the table and execute the queries given below.

TABLE STRUCTURE:

FIELD NAME Roll No. Student Name Mark 1 Mark 2 Mark 3 Total Grade

DATATYPE Numeric Alpha Numeric Numeric Numeric Numeric Numeric Characters

SIZE 4 14 3 3 3 3 1

CONSTRAINTS Primary Key Not Null Not Null Not null Not Null ---Nil-----Nil---

TABLE CREATION:

SQL> create table studentmarklist ( rollno number(4) constraints pkey primary key, sname varchar2(14) not null, mark1 number(3) not null, mark2 number(3) not null, mark3 number(3) not null, total number(3), grade varchar2(1) ); Table created.

TABLE DESCRIPTION: SQL> desc studentmarklist; Name Null? Type ----------------------------------------- -------- ---------------------------ROLLNO NOT NULL NUMBER(4) SNAME NOT NULL VARCHAR2(14) MARK1 NOT NULL NUMBER(3) MARK2 NOT NULL NUMBER(3) MARK3 NOT NULL NUMBER(3) TOTAL NUMBER(3) GRADE VARCHAR2(1)

INSERTING-RECORDS : SQL> insert into studentmarklist ( rollno, sname, mark1, mark2, mark3 ) values ( '&rollno', '&sname', '&mark1', '&mark2', '&mark3' ); Enter value for rollno: 111 Enter value for sname: aaa Enter value for mark1: 85 Enter value for mark2: 89 Enter value for mark3: 90 1 row created. SQL> / Enter value for rollno: 222 Enter value for sname: bbb Enter value for mark1: 55 Enter value for mark2: 60 Enter value for mark3: 50 1 row created. SQL> / Enter value for rollno: 333 Enter value for sname: ccc Enter value for mark1: 50 Enter value for mark2: 51 Enter value for mark3: 47 1 row created.

SQL> / Enter value for rollno: 444 Enter value for sname: ddd Enter value for mark1: 35 Enter value for mark2: 40 Enter value for mark3: 20 1 row created.

UPDATING: SQL> update studentmarklist set total=mark1+mark2+mark3; 4 rows updated. SQL> update studentmarklist set grade = 'O 'where total>200; 1 row updated. SQL> update studentmarklist set grade = 'A' where total >=150 and total <=200; 1 row updated. SQL> update studentmarklist set grade = 'B' where total>100 and total<=149; 1 row updated. SQL> update studentmarklist set grade='F' where total<100; 1 row updated. TABLE RECORDS: SQL> select * from studentmarklist; ROLLNO SNAME MARK1 MARK2 MARK3 TOTAL G ----------------------------------------------------------------------------------------------------111 aaa 85 89 90 264 O 222 bbb 55 60 50 165 A 333 ccc 50 51 47 148 B 444 ddd 35 40 20 95 F 4 Rows selected.

QUERIES: 1) Display the students name which starts with the letter s. SQL> select sname from studentmarklist where sname like 's%'; no rows selected 2) Display the students name which starts with the letter a. SQL> select sname from studentmarklist where sname like 'a%'; SNAME -------------aaa 3) Display the students record whose name starts with letter a. SQL> select * from studentmarklist where sname like 'a%'; ROLLNO SNAME MARK1 MARK2 MARK3 TOTAL G ----------------------------------------------------------------------------------------------111 aaaa 85 89 90 264 O 4) Display the students name which ends with the letter c. SQL> select sname from studentmarklist where sname like '%c'; SNAME ----------ccc 5) Display the students record whose name ends with the letter c. SQL> select * from studentmarklist where sname like '%c'; ROLLNO SNAME MARK1 MARK2 MARK3 TOTAL G --------------------------------------------------------------------------------------------333 ccc 50 51 47 148 B

6) Display the students record who have got more than 80 in all subjects. SQL> select * from studentmarklist where mark1>80 and mark2>80 and mark3>80; ROLLNO SNAME MARK1 MARK2 MARK3 TOTAL G ---------------------------------------------------------------------------------------------111 aaa 85 89 90 264 O

7) Display the maximum total of marks obtained. SQL> select max(total)from studentmarklist; MAX(TOTAL) -----------------264 8) Display the minimum total of marks obtained. SQL> select min(total) from studentmarklist; MIN(TOTAL) ----------------95 9) Display the students record who have got the grade F. SQL> select * from studentmarklist where grade='f'; ROLLNO SNAME MARK1 MARK2 MARK3 TOTAL G -----------------------------------------------------------------------------------------------444 ddd 35 40 20 95 F 10) Display the students record who have got the grade O. SQL> select * from studentmarklist where grade = 'O' ; ROLLNO SNAME MARK1 MARK2 MARK3 TOTAL G ------------------------------------------------------------------------------------------------111 aaa 85 89 90 264 O

RESULT: Thus the student table is created and the above queries are executed successfully.

STUDENT MARKLIST-2
AIM: Create the following table and insert records into the table and execute the queries given below.

TABLE STRUCTURE 1:

Field name Rollno Name

Data type Number Alphanumeric

Size 3 14

Constraints Primary key Not Null

TABLE STRUCTURE 2: Field name Rollno Mark1 Mark2 Mark3 Total Grade Data type Number(3) Number(3) Number(3) Number(3) Number(3) Alphanumeric Size 3 3 3 3 3 1 Constraints Foreign Key Between 0 and 100 Between 0 and 100 Between 0 and 100 -

TABLE CREATION:
MASTER TABLE CREATION:

SQL> create table student(rollno number(3) constraints prollno primary key, sname varchar2(14) constraints non not null); Table created. TABLE DESCRIPTION: SQL> desc student; Name Null? Type --------------------------------------- ---------------- ------------------------ROLLNO NOT NULL NUMBER(3) SNAME NOT NULL VARCHAR2(14)
CHILD TABLE CREATION:

SQL> create table cstudent( rollno number(3) constraints csid references student(rollno) on delete cascade, mark1 number(3) constraints chk1 check(mark1 between 0 and100), mark2 number(3) constraints chk2 check(mark2 between 0 and 100), mark3 number(3) constraints chk3 check(mark3 between 0 and 100), total number(5), grade varchar2(1)); Table created. TABLE DESCRIPTION: SQL> desc cstudent; Name Null? Type ----------------------------------------- -------- --------------------ROLLNO NUMBER(3) MARK1 NUMBER(3) MARK2 NUMBER(3) MARK3 NUMBER(3) TOTAL NUMBER(5) GRADE VARCHAR2(1)

INSERTING RECORDS: SQL> insert into student(rollno,sname)values('&rollno','&sname'); Enter value for rollno: 1 Enter value for sname: suchi 1 row created. SQL> / Enter value for rollno: 2 Enter value for sname: sruthi 1 row created.

UPDATING RECORDS: SQL> update cstudent set total=mark1+mark2+mark3; 4 rows updated. SQL> update cstudent set grade='O' where total>250; 1 row updated. SQL> update cstudent set grade='A' where total<=249 and total>200; 3 rows updated. SQL> update cstudent set grade='B' where total<=199 and total>150; 1 row updated. SQL> update cstudent set grade='C' where total<=149 and total>100; 1 row updated. SQL> update cstudent set grade='F' where total<=99; 1 row updated.

QUERIES:

1) To display the students records whose name starts with s : SQL> select * from student where sname like 's%'; ROLLNO -----------1 2 SNAME -------------suchi sruthi

2) To display the students records whose name ends with n: SQL> select * from student where sname like '%n'; ROLLNO SNAME ------------ ----------3 naveen 3) To display the students records who have secured more than 150: SQL> select * from cstudent where total>150; ROLLNO MARK1 MARK2 MARK3 TOTAL GRADE ------------ ---------- ------------ ---------- ---------- ---------1 82 75 92 249 A 3 76 45 65 186 B 4 100 78 82 260 O 4) To display the students record who have secured the maximum total: SQL> select max(total) from cstudent; MAX(TOTAL) -----------------260 5) To display the students records who have got c grade: SQL> select * from cstudent where grade='C'; ROLLNO MARK1 MARK2 MARK3 TOTAL GRADE ------------ ---------- ----------- ----------- ---------- ----------2 50 60 30 140 C

6) To display the student record who have got o grade: SQL> select * from cstudent where grade='O'; ROLLNO MARK1 MARK2 MARK3 TOTAL GRADE ------------- ---------- ----------- ---------- ---------- ----------4 100 78 82 260 O

7) To display the students records who have secured the second maximum total: SQL> select max(total) from cstudent where total <(select max(total) from cstudent); MAX(TOTAL) ------------------249

Result: Thus the student tables are created and the above queries are executed successfully.

You might also like