0% found this document useful (0 votes)
42 views53 pages

DMS Report

Uploaded by

yuvrajgandhmal
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)
42 views53 pages

DMS Report

Uploaded by

yuvrajgandhmal
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/ 53

Maharashtra state Board of

technical education, MuMBai

GOVERNMENT
POLYTECHNIC,SOLAPUR

DIPLOMA IN COMPUTER
TECHNOLOGY
ACADEMIC YEAR 2023-24
DATABASE MANAGEMENT SYSTEM
A
MICRO-PROJECT
ON

Online Coaching Institute Database

Submitted by :

Roll Name Enrolment


Number Number

55 Yuvraj Manoj Gandhmal 23210230275


84 Shruti Arvind Gajul 23210230305

Submitted to: Prof. Ravi Gangundi


1
2
CERTIFICATE
MAHARASHTRA STATE BOARD OF TECHNICAL
EDUCATION, MUMBAI

GOVERNMENT POLYTECHNIC, SOLAPUR

Title of microproject- Online Coaching Institute Database

This is to certify that the following students Yuvraj Gandhmal , Shruti


Gajul Roll no 55,84 enrolments no 23210230275 and 23210230305
of Branch Computer of semester third (3) of diploma in Computer
Technology of institute Government Polytechnic, Solapur. Code
(0015) have completed themicroproject work satisfactorily under my
supervision /guidance for the subject DATABASE MANAGEMENT
SYSTEM in the academic year 2024-2025 as prescribed in the
curriculum.

Guide Name -Prof. Gangundi sir

Date & Sign -

HOD PRINCIPAL

3
CONTENTS:

SR No. CONTENTS Page No.

1. INTRODUCTION 5

2. ER DIAGRAM 6

3. NORMALIZATION 7

4. FINAL TABLES 18

5. CONSTRAINTS 22

6. MICROPROJECT CODE 26

7. SQL COMMANDS ON TABLES 37

8. PL-SQL COMMANDS ON TABLES 42

9. RESOURCES USED 52

10. CONCLUSION 53

4
introduction

The evolution of online education has accelerated,


especially since the onset of the COVID-19 pandemic.
Online coaching classes have become increasingly
popular, especially with the advancement of e-learning
technologies. These platforms require robust database
systems to handle diverse data elements, including
student information, course content, attendance
records, progress tracking, and payment details. Studies
show that a well-designed database is crucial for
organizing and managing the large volume of data
associated with online learning, ensuring efficiency and
scalability. The system facilitates effective data
management, enhances user experience, and supports
smooth operation for students, instructors, and
administrators in online coaching class database
focuses on principles of data organization, storage,
retrieval, and the functions needed to facilitate a virtual
learning environment.

5
er diaGraM

6
norMaliZation

1.Course

1NF: The COURSE table is in 1NF because:


* It has a primary key (Course_id) that uniquely identifies each row.
* All columns are atomic, meaning each column contains only one value per
attribute (e.g., Course_name, Course_fees, st_date, end_date, stud_count).
* There are no repeating groups or multi-valued attributes.

2NF: The table meets 2NF because:


* It is already in 1NF.
* All non-key attributes (Course_name, Course_fees, st_date, end_date, and
stud_count) depend fully on the primary key (Course_id). Since Course_id is
a single-column primary key, there’s no chance of partial dependency on a
composite key.

3NF: The table is in 3NF because:


* It is in 2NF.
* There are no transitive dependencies, meaning non-key attributes do not
depend on other non-key attributes. For example, Course_fees does not
depend on Course_name or st_date; it depends only on the primary key,
Course_id. This ensures all non-key attributes are solely dependent on
Course_id and meet the 3NF requirement.

7
2.Student

1NF: The STUDENT table is in 1NF because:


- It has a primary key (Stud_id) that uniquely identifies each row.
- All columns are atomic, meaning each column contains only one value per
attribute (e.g., each student has only one Phone_no).
- There are no repeating groups or multi-valued attributes.
2NF: The table meets 2NF because:
- It is already in 1NF.
- All non-key attributes (S_fname, S_lname, DOB, City, Gender, Phone_no, Email,
Clg_name, and Course_id) depend fully on the primary key (Stud_id). Since Stud_id
is a single-column primary key, there’s no chance of partial dependency on a
composite key.
3NF: The table is in 3NF because:
- It is in 2NF.
- There are no transitive dependencies, meaning non-key attributes do not depend
on other non-key attributes. For example, Course_id does not depend on Clg_name
or City; it depends only on the primary key, Stud_id. This ensures all non-key
attributes are solely dependent on Stud_id and meet the 3NF requirement.

8
3.Staff

1NF: The Staff table is in 1NF because:


- It has a primary key (Staff_id) that uniquely identifies each row.
- All columns contain atomic values, meaning each column holds only one value per
attribute (e.g., each staff member has a single Staff_phno and Staff_email).
- There are no repeating groups or multi-valued attributes.
2NF: The table meets 2NF because:
- It is already in 1NF.
- All non-key attributes (Staff_fname, Staff_lname, Staff_email, Staff_phno,
Specialization, DOJ, Experience, sal) depend fully on the primary key (Staff_id).
Since Staff_id is a single-column primary key, there’s no chance of partial
dependency on a composite key.
3NF: The table is in 3NF because:
- It is in 2NF.
- There are no transitive dependencies, meaning non-key attributes do not depend
on other non-key attributes. For example, Specialization does not depend on DOJ
or Experience; it depends only on the primary key, Staff_id. This ensures all non-key
attributes are solely dependent on Staff_id and meet the 3NF requirement.

9
4.Staff_sal

1NF: The Staff_sal table is in 1NF because:


- It has a composite primary key (Staff_id, Month) that uniquely identifies each row.
- All columns contain atomic values, meaning each column holds only one value per
attribute (e.g., Working_days, Leave_days, Actual_sal, Paid_sal, and
Transaction_no).
- There are no repeating groups or multi-valued attributes.

2NF: The table meets 2NF because:


- It is already in 1NF.
- All non-key attributes (Working_days, Leave_days, Actual_sal, Paid_sal,
Transaction_no) depend fully on the composite primary key (Staff_id, Month).
There is no partial dependency, as each attribute relates to both Staff_id and
Month.

3NF: The table is in 3NF because:


- It is in 2NF.
- There are no transitive dependencies, meaning no non-key attributes depend on
other non-key attributes. Each non-key attribute (Working_days, Leave_days,
Actual_sal, Paid_sal, Transaction_no) depends only on the composite primary key
(Staff_id, Month).

10
5.Stf_crs_ass

1NF: The STF_CRS_ASS table is in 1NF because:


- It has a composite primary key (Staff_id, Course_id) that uniquely identifies
each row.
- All columns contain atomic values, meaning each column holds only one
value per attribute (e.g., each row records a single Staff_id and Course_id
pairing).
- There are no repeating groups or multi-valued attributes.

2NF: The table meets 2NF because:


- It is already in 1NF.
- All non-key attributes depend fully on the composite primary key (Staff_id,
Course_id). Since the table has no additional non-key attributes beyond the
composite key, there is no partial dependency.

3NF: The table is in 3NF because:


- It is in 2NF.
- There are no transitive dependencies, meaning there are no non-key
attributes that depend on other non-key attributes. Each column depends
only on the primary key (Staff_id, Course_id), ensuring all non-key attributes
(if they existed) would be dependent solely on the primary key.

11
6.Fees

1NF: The Fees table is in 1NF because:


- It has a primary key (Transaction_id) that uniquely identifies each row.
- All columns contain atomic values, meaning each column holds only one
value per attribute (e.g., Stud_id, Course_id, Fees_paid, and Payment_date).
- There are no repeating groups or multi-valued attributes.

2NF: The table meets 2NF because:


- It is already in 1NF.
- All non-key attributes (Stud_id, Course_id, Fees_paid, Payment_date)
depend fully on the primary key (Transaction_id). There is no partial
dependency, as Transaction_id is a single-column primary key.

3NF: The table is in 3NF because:


- It is in 2NF.
- There are no transitive dependencies, meaning no non-key attributes
depend on other non-key attributes. For example, Fees_paid depends
directly on the primary key (Transaction_id), and Stud_id depends only on
Transaction_id (via the foreign key). There are no indirect dependencies on
other non-key attributes.

12
7.C

1NF: The C table is in 1NF because:


- It has a primary key (Stud_id), implicitly referenced via the foreign key from
the STUDENT table, that uniquely identifies each row.
- All columns contain atomic values, meaning each column holds only one
value per attribute (e.g., S_fname, S_lname, T1_marks, T2_marks, T3_marks,
Total_marks, Avg_marks, and Grade).
- There are no repeating groups or multi-valued attributes.
2NF: The table meets 2NF because:
- It is already in 1NF.
- All non-key attributes (S_fname, S_lname, T1_marks, T2_marks, T3_marks,
Total_marks, Avg_marks, Grade) depend fully on the primary key (Stud_id).
There is no partial dependency, as Stud_id is the only key and the table has
no composite key.
3NF: The table is in 3NF because:
- It is in 2NF.
- There are no transitive dependencies, meaning non-key attributes do not
depend on other non-key attributes. For example, Total_marks and
Avg_marks depend directly on the Stud_id, and Grade depends directly on
Avg_marks (which is derived from Total_marks), but there are no indirect
dependencies that violate 3NF.

13
8.CPP

1NF: The CPP table is in 1NF because:


- It has a foreign key (Stud_id) that uniquely identifies each row.
- All columns contain atomic values, meaning each column holds only one
value per attribute (e.g., S_fname, S_lname, T1_marks, T2_marks, T3_marks,
Total_marks, Avg_marks, and Grade).
- There are no repeating groups or multi-valued attributes.

2NF: The table meets 2NF because:


- It is already in 1NF.
- All non-key attributes (S_fname, S_lname, T1_marks, T2_marks, T3_marks,
Total_marks, Avg_marks, Grade) depend fully on the primary key (Stud_id).
There is no partial dependency, as Stud_id is the only key and the table has
no composite key.

3NF: The table is in 3NF because:


- It is in 2NF.
- There are no transitive dependencies, meaning non-key attributes do not
depend on other non-key attributes. For example, Total_marks and
Avg_marks depend directly on Stud_id, and Grade depends directly on
Avg_marks (which is derived from Total_marks), but there are no indirect
dependencies that violate 3NF.

14
9.Python

1NF: The Python table is in 1NF because:


- It has a foreign key (Stud_id) that references the primary key of the
STUDENT table and helps uniquely identify each row.
- All columns contain atomic values, meaning each column holds only one
value per attribute (e.g., S_fname, S_lname, T1_marks, T2_marks, T3_marks,
Total_marks, Avg_marks, and Grade).
- There are no repeating groups or multi-valued attributes.

2NF: The table meets 2NF because:


- It is already in 1NF.
- All non-key attributes (S_fname, S_lname, T1_marks, T2_marks, T3_marks,
Total_marks, Avg_marks, Grade) depend fully on the primary key (Stud_id).
There is no partial dependency, as Stud_id is the only key and the table has
no composite key.

3NF: The table is in 3NF because:


- It is in 2NF.
- There are no transitive dependencies, meaning non-key attributes do not
depend on other non-key attributes. For example, Total_marks and
Avg_marks depend directly on Stud_id, and Grade depends directly on
Avg_marks (which is derived from Total_marks), but there are no indirect
dependencies that violate 3NF.
15
10.Java

1NF: The Java table is in 1NF because:


- It has a foreign key (Stud_id) that references the primary key of the
STUDENT table and helps uniquely identify each row.
- All columns contain atomic values, meaning each column holds only one
value per attribute (e.g., S_fname, S_lname, T1_marks, T2_marks, T3_marks,
Total_marks, Avg_marks, and Grade).
- There are no repeating groups or multi-valued attributes.
2NF: The table meets 2NF because:
- It is already in 1NF.
- All non-key attributes (S_fname, S_lname, T1_marks, T2_marks, T3_marks,
Total_marks, Avg_marks, Grade) depend fully on the primary key (Stud_id).
There is no partial dependency, as Stud_id is the only key and the table has
no composite key.
3NF: The table is in 3NF because:
- It is in 2NF.
- There are no transitive dependencies, meaning non-key attributes do not
depend on other non-key attributes. For example, Total_marks and
Avg_marks depend directly on Stud_id, and Grade depends directly on
Avg_marks (which is derived from Total_marks), but there are no indirect
dependencies that violate 3NF.

16
11.DBMS

1NF: The DBMS table is in 1NF because:


- It has a foreign key (Stud_id) that references the primary key of the
STUDENT table and helps uniquely identify each row.
- All columns contain atomic values, meaning each column holds only one
value per attribute (e.g., S_fname, S_lname, T1_marks, T2_marks, T3_marks,
Total_marks, Avg_marks, and Grade).
- There are no repeating groups or multi-valued attributes.
2NF: The table meets 2NF because:
- It is already in 1NF.
- All non-key attributes (S_fname, S_lname, T1_marks, T2_marks, T3_marks,
Total_marks, Avg_marks, Grade) depend fully on the primary key (Stud_id).
There is no partial dependency, as Stud_id is the only key and the table has
no composite key.
3NF: The table is in 3NF because:
- It is in 2NF.
- There are no transitive dependencies, meaning non-key attributes do not
depend on other non-key attributes. For example, Total_marks and
Avg_marks depend directly on Stud_id, and Grade depends directly on
Avg_marks (which is derived from Total_marks), but there are no indirect
dependencies that violate 3NF.

17
final taBles

Table For Course

Table For Student

18
Table For Staff

Table For Staff_sal

Table For Stf_crs_ass

19
Table For Fees

Table For C

20
Table For CPP

Table For Python

Table For Java

Table For DBMS

21
constraints
Table 1: COURSE
1. Primary Key (PK): Course_id
2. Not Null: Course_name

Table 2: STUDENT
1. Primary Key (PK): Stud_id
2. Not Null: S_fname, S_lname
3. Check Constraint: Gender (allowed values: 'MALE', 'FEMALE')
4. Check Constraint: Phone_no (must be 10 digits)
5. Unique Constraint: Email
6. Foreign Key (FK): Course_id (references Course.Course_id with
ON DELETE CASCADE)

Table 3: STAFF
1. Primary Key (PK): Staff_id
2. Check Constraint: Staff_phno (must be 10 characters)
3. Unique Constraint: sal

Table 4: STF_CRS_ASS
1. Primary Key (PK): Combination of Staff_id and Course_id
2. Foreign Key (FK): Staff_id (references STAFF.Staff_id )
3. Foreign Key (FK): Course_id (references COURSE.Course_id with
ON DELETE CASCADE)

22
Table 5: STAFF_SAL
1. Primary Key (PK): Combination of Staff_id and Month
2. Not Null: Working_days
3. Default Value: Leave_days (default is 0)
4. Check Constraint: Actual_sal (must be greater than 15000)
5. Unique Constraint: Transaction_no
6. Foreign Key (FK): Staff_id (references Staff.Staff_id with ON
DELETE CASCADE)

Table 6: Fees
1. Primary Key (PK): Transaction_id
2. Foreign Key (FK): Stud_id (references STUDENT(Stud_id))
3. Not Null: Fees_paid

Table 7: C
1. Foreign Key (FK): Stud_id (references STUDENT(Stud_id))
2. Not Null: S_fname, S_Lname
3. Check Constraints:
o T1_marks (T1_marks >= 0 AND T1_marks <= 100)

o T2_marks (T2_marks >= 0 AND T2_marks <= 100)

o T3_marks (T3_marks >= 0 AND T3_marks <= 100)

o Total_marks (Total_marks >= 0 AND Total_marks <= 300)

o Percentage (Percentage >= 0 AND Percentage <= 100)

o Grade (Grade IN ('A', 'B', 'C', 'F'))

23
Table 8: CPP
1. Foreign Key (FK): Stud_id (references STUDENT(Stud_id))
2. Not Null: S_fname, S_Lname
3. Check Constraints:
o T1_marks (T1_marks >= 0 AND T1_marks <= 100)

o T2_marks (T2_marks >= 0 AND T2_marks <= 100)

o T3_marks (T3_marks >= 0 AND T3_marks <= 100)

o Total_marks (Total_marks >= 0 AND Total_marks <= 300)

o Percentage (Percentage >= 0 AND Percentage <= 100)

o Grade (Grade IN ('A', 'B', 'C', 'F'))

Table 9: Python
1. Foreign Key (FK): Stud_id (references STUDENT(Stud_id))
2. Not Null: S_fname, S_Lname
3. Check Constraints:
o T1_marks (T1_marks >= 0 AND T1_marks <= 100)

o T2_marks (T2_marks >= 0 AND T2_marks <= 100)

o T3_marks (T3_marks >= 0 AND T3_marks <= 100)

o Total_marks (Total_marks >= 0 AND Total_marks <= 300)

o Percentage (Percentage >= 0 AND Percentage <= 100)

o Grade (Grade IN ('A', 'B', 'C', 'F'))

24
Table 10: Java
1. Foreign Key (FK): Stud_id (references STUDENT(Stud_id))
2. Not Null: S_fname, S_Lname
3. Check Constraints:
o T1_marks (T1_marks >= 0 AND T1_marks <= 100)

o T2_marks (T2_marks >= 0 AND T2_marks <= 100)

o T3_marks (T3_marks >= 0 AND T3_marks <= 100)

o Total_marks (Total_marks >= 0 AND Total_marks <= 300)

o Percentage (Percentage >= 0 AND Percentage <= 100)

o Grade (Grade IN ('A', 'B', 'C', 'F'))

Table 11: DBMS


1. Foreign Key (FK): Stud_id (references STUDENT(Stud_id))
2. Not Null: S_fname, S_Lname
3. Check Constraints:
o T1_marks (T1_marks >= 0 AND T1_marks <= 100)

o T2_marks (T2_marks >= 0 AND T2_marks <= 100)

o T3_marks (T3_marks >= 0 AND T3_marks <= 100)

o Total_marks (Total_marks >= 0 AND Total_marks <= 300)

o Percentage (Percentage >= 0 AND Percentage <= 100)

o Grade (Grade IN ('A', 'B', 'C', 'F'))

25
Microproject code
<<<<---CREATING TABLES--->>>>

CREATE TABLE COURSE


( Course_id number(2),
Course_name varchar2(20) NOT NULL,
Course_fees number(5),
st_date date,
end_date date,
stud_count number(4),
CONSTRAINT pk_course_id PRIMARY KEY(Course_id)
);

CREATE TABLE STUDENT


( Stud_id NUMBER(4) CONSTRAINT pk_stud_id PRIMARY KEY,
S_fname VARCHAR2(20) NOT NULL,
S_lname VARCHAR2(20) NOT NULL,
DOB DATE,
City VARCHAR2(15),
Gender VARCHAR2(6) CHECK (Gender = 'MALE' OR Gender = 'FEMALE'),
Phone_no NUMBER(10) CHECK (LENGTH(Phone_no) = 10),
Email VARCHAR2(30) UNIQUE,
Clg_name VARCHAR2(30),
Course_id NUMBER(2),
CONSTRAINT fk_course_id FOREIGN KEY (Course_id) REFERENCES COURSE(Course_id)
ON DELETE CASCADE
);

CREATE TABLE Staff


( Staff_id number(3) CONSTRAINT pk_staff_id PRIMARY KEY,
Staff_fname varchar2(20),
Staff_lname varchar2(20),
Staff_email varchar2(30),
Staff_phno varchar2(10) CHECK (length(Staff_phno)=10),
Specialization varchar2(20),
26
DOJ date,
Experience number(2),
sal number(8,2)unique
);

CREATE TABLE STF_CRS_ASS (


Staff_id NUMBER(3),
Course_id NUMBER(2),
CONSTRAINT pk_staff_course PRIMARY KEY (Staff_id, Course_id),
CONSTRAINT fk_staff FOREIGN KEY (Staff_id) REFERENCES STAFF(Staff_id) ON DELETE
CASCADE,
CONSTRAINT fk_course FOREIGN KEY (Course_id) REFERENCES COURSE(Course_id) ON
DELETE CASCADE
);

CREATE TABLE Staff_sal (


Staff_id NUMBER(3),
Month CHAR(3),
Working_days NUMBER(3) NOT NULL,
Leave_days NUMBER(3) DEFAULT 0,
Actual_sal NUMBER(8,2) CHECK (Actual_sal > 15000),
Paid_sal NUMBER(8,2),
Transaction_no NUMBER(16),
CONSTRAINT pk_staff_sal PRIMARY KEY (Staff_id, Month),
CONSTRAINT uk_transaction_no UNIQUE (Transaction_no),
CONSTRAINT fk_staff_sal_id FOREIGN KEY (Staff_id) REFERENCES Staff(Staff_id) ON
DELETE CASCADE
);

CREATE TABLE Fees (


Stud_id NUMBER(4),
Transaction_id NUMBER(16) PRIMARY KEY,
Course_id NUMBER(3),
Fees_paid NUMBER(5) NOT NULL,
Payment_date DATE,
CONSTRAINT fkcourse_stud_id FOREIGN KEY (Stud_id) REFERENCES STUDENT(Stud_id)
);
27
CREATE TABLE C
( Stud_id NUMBER(4),
S_fname VARCHAR2(20) NOT NULL,
S_Lname VARCHAR2(20) NOT NULL,
T1_marks NUMBER(3) CHECK (T1_marks>=0 AND T1_marks<=100),
T2_marks NUMBER(3) CHECK (T2_marks>=0 AND T2_marks<=100),
T3_marks NUMBER(3) CHECK (T3_marks>=0 AND T3_marks<=100),
Total_marks NUMBER(3) CHECK (Total_marks>=0 AND Total_marks<=300),
Percentage NUMBER(4,2) CHECK (Percentage>=0 AND Percentage<=100),
Grade CHAR(1) CHECK (Grade IN('A','B','C','F')),
CONSTRAINT fk_stud_id FOREIGN KEY (Stud_id) REFERENCES STUDENT(Stud_id)
);

CREATE TABLE CPP


( Stud_id NUMBER(4),
S_fname VARCHAR2(20) NOT NULL,
S_Lname VARCHAR2(20) NOT NULL,
T1_marks NUMBER(3) CHECK (T1_marks>=0 AND T1_marks<=100),
T2_marks NUMBER(3) CHECK (T2_marks>=0 AND T2_marks<=100),
T3_marks NUMBER(3) CHECK (T3_marks>=0 AND T3_marks<=100),
Total_marks NUMBER(3) CHECK (Total_marks>=0 AND Total_marks<=300),
Percentage NUMBER(4,2) CHECK (Percentage>=0 AND Percentage<=100),
Grade CHAR(1) CHECK (Grade IN('A','B','C','F')),
CONSTRAINT fk_stud_cpp_id FOREIGN KEY (Stud_id) REFERENCES STUDENT(Stud_id)
);

CREATE TABLE Python


( Stud_id NUMBER(4),
S_fname VARCHAR2(20) NOT NULL,
S_Lname VARCHAR2(20) NOT NULL,
T1_marks NUMBER(3) CHECK (T1_marks>=0 AND T1_marks<=100),
T2_marks NUMBER(3) CHECK (T2_marks>=0 AND T2_marks<=100),
T3_marks NUMBER(3) CHECK (T3_marks>=0 AND T3_marks<=100),
Total_marks NUMBER(3) CHECK (Total_marks>=0 AND Total_marks<=300),
Percentage NUMBER(4,2) CHECK (Percentage>=0 AND Percentage<=100),

28
Grade CHAR(1) CHECK (Grade IN('A','B','C','F')),
CONSTRAINT fk_stud_py_id FOREIGN KEY (Stud_id) REFERENCES STUDENT(Stud_id)
);

CREATE TABLE Java


( Stud_id NUMBER(4),
S_fname VARCHAR2(20) NOT NULL,
S_Lname VARCHAR2(20) NOT NULL,
T1_marks NUMBER(3) CHECK (T1_marks>=0 AND T1_marks<=100),
T2_marks NUMBER(3) CHECK (T2_marks>=0 AND T2_marks<=100),
T3_marks NUMBER(3) CHECK (T3_marks>=0 AND T3_marks<=100),
Total_marks NUMBER(3) CHECK (Total_marks>=0 AND Total_marks<=300),
Percentage NUMBER(4,2) CHECK (Percentage>=0 AND Percentage<=100),
Grade CHAR(1) CHECK (Grade IN('A','B','C','F')),
CONSTRAINT fk_stud_java_id FOREIGN KEY (Stud_id) REFERENCES STUDENT(Stud_id)
);

CREATE TABLE DBMS


( Stud_id NUMBER(4),
S_fname VARCHAR2(20) NOT NULL,
S_Lname VARCHAR2(20) NOT NULL,
T1_marks NUMBER(3) CHECK (T1_marks>=0 AND T1_marks<=100),
T2_marks NUMBER(3) CHECK (T2_marks>=0 AND T2_marks<=100),
T3_marks NUMBER(3) CHECK (T3_marks>=0 AND T3_marks<=100),
Total_marks NUMBER(3) CHECK (Total_marks>=0 AND Total_marks<=300),
Percentage NUMBER(4,2) CHECK (Percentage>=0 AND Percentage<=100),
Grade CHAR(1) CHECK (Grade IN('A','B','C','F')),
CONSTRAINT fk_stud_dbms_id FOREIGN KEY (Stud_id) REFERENCES
STUDENT(Stud_id)
);

29
<<<<<----Inserting data in tables--->>>>>

----1.Inserting 5 rows in Course Table----

INSERT ALL
INTO COURSE VALUES(41, 'C LANG', 5000, TO_DATE('12-OCT-2022', 'DD-MON-YYYY'),
TO_DATE('22-JAN-2023', 'DD-MON-YYYY'), 100, 121)
INTO COURSE VALUES(42, 'CPP LANG', 6000, TO_DATE('02-MAR-2023', 'DD-MON-
YYYY'), TO_DATE('19-MAY-2023', 'DD-MON-YYYY'), 140, 123)
INTO COURSE VALUES(43, 'PYTHON LANG', 7000, TO_DATE('30-JUN-2021', 'DD-MON-
YYYY'), TO_DATE('28-OCT-2021', 'DD-MON-YYYY'), 160, 124)
INTO COURSE VALUES(44, 'JAVA LANG', 6500, TO_DATE('24-SEP-2022', 'DD-MON-
YYYY'), TO_DATE('01-FEB-2023', 'DD-MON-YYYY'), 200, 122)
INTO COURSE VALUES(45, 'DBMS LANG', 7000, TO_DATE('15-APR-2024', 'DD-MON-
YYYY'), TO_DATE('07-JUN-2024', 'DD-MON-YYYY'), 150, 125)
SELECT * FROM DUAL;

----2.Inserting 25 rows in Student table-----

INSERT ALL
INTO STUDENT VALUES (2101, 'Aarav', 'Sharma', TO_DATE('15-FEB-2005', 'DD-MON-
YYYY'), 'Delhi', 'MALE', 9123456789, '[email protected]', 'DCE', 41)
INTO STUDENT VALUES (2102, 'Vivaan', 'Gupta', TO_DATE('22-JUL-2006', 'DD-MON-
YYYY'), 'Mumbai', 'MALE', 9234567890, '[email protected]', 'VJTI', 42)
INTO STUDENT VALUES (2103, 'Anaya', 'Khan', TO_DATE('11-SEP-2004', 'DD-MON-
YYYY'), 'Bangalore', 'FEMALE', 9345678901, '[email protected]', 'BIT', 43)
INTO STUDENT VALUES (2104, 'Reyansh', 'Mehta', TO_DATE('08-NOV-2007', 'DD-MON-
YYYY'), 'Hyderabad', 'MALE', 9123456780, '[email protected]', 'JNTU', 44)
INTO STUDENT VALUES (2105, 'Saanvi', 'Nair', TO_DATE('30-APR-2005', 'DD-MON-
YYYY'), 'Chennai', 'FEMALE', 9988776655, '[email protected]', 'AU', 45)
INTO STUDENT VALUES (2106, 'Krishna', 'Iyer', TO_DATE('19-JAN-2006', 'DD-MON-
YYYY'), 'Pune', 'MALE', 9876543210, '[email protected]', 'CEP', 41)
INTO STUDENT VALUES (2107, 'Nisha', 'Verma', TO_DATE('12-MAR-2007', 'DD-MON-
YYYY'), 'Ahmedabad', 'FEMALE', 9765432109, '[email protected]', 'NU', 42)
INTO STUDENT VALUES (2108, 'Arjun', 'Patel', TO_DATE('21-JUN-2005', 'DD-MON-
YYYY'), 'Surat', 'MALE', 9654321098, '[email protected]', 'SVPIET', 43)
INTO STUDENT VALUES (2109, 'Diya', 'Reddy', TO_DATE('25-OCT-2006', 'DD-MON-
YYYY'), 'Visakhapatnam', 'FEMALE', 9543210987, '[email protected]', 'GITAM', 44)
30
INTO STUDENT VALUES (2110, 'Rohan', 'Singh', TO_DATE('03-DEC-2004', 'DD-MON-
YYYY'), 'Jaipur', 'MALE', 9432109876, '[email protected]', 'MNIT', 45)
INTO STUDENT VALUES (2111, 'Pooja', 'Gupta', TO_DATE('14-FEB-2007', 'DD-MON-
YYYY'), 'Lucknow', 'FEMALE', 9321098765, '[email protected]', 'IIEST', 41)
INTO STUDENT VALUES (2112, 'Sai', 'Kumar', TO_DATE('17-JUL-2005', 'DD-MON-YYYY'),
'Coimbatore', 'MALE', 9108765432, '[email protected]', 'PSG', 42)
INTO STUDENT VALUES (2113, 'Tanya', 'Nair', TO_DATE('10-SEP-2006', 'DD-MON-
YYYY'), 'Mysore', 'FEMALE', 9265432108, '[email protected]', 'JSS', 43)
INTO STUDENT VALUES (2114, 'Aditya', 'Srinivasan', TO_DATE('20-OCT-2004', 'DD-
MON-YYYY'), 'Chennai', 'MALE', 9356781234, '[email protected]', 'IITM', 44)
INTO STUDENT VALUES (2115, 'Nitya', 'Desai', TO_DATE('24-NOV-2006', 'DD-MON-
YYYY'), 'Delhi', 'FEMALE', 9445678901, '[email protected]', 'IITD', 45)
INTO STUDENT VALUES (2116, 'Karan', 'Mehta', TO_DATE('09-DEC-2005', 'DD-MON-
YYYY'), 'Ahmedabad', 'MALE', 9534567890, '[email protected]', 'LDCE', 41)
INTO STUDENT VALUES (2117, 'Ananya', 'Chowdhury', TO_DATE('15-JAN-2007', 'DD-
MON-YYYY'), 'Bhopal', 'FEMALE', 9678901234, '[email protected]',
'MANIT', 42)
INTO STUDENT VALUES (2118, 'Rahul', 'Bhattacharya', TO_DATE('28-FEB-2006', 'DD-
MON-YYYY'), 'Indore', 'MALE', 9567890123, '[email protected]', 'IIST', 43)
INTO STUDENT VALUES (2119, 'Siddhi', 'Iyer', TO_DATE('01-MAR-2005', 'DD-MON-
YYYY'), 'Vadodara', 'FEMALE', 9456789012, '[email protected]', 'VIT', 44)
INTO STUDENT VALUES (2120, 'Rishabh', 'Jha', TO_DATE('29-APR-2006', 'DD-MON-
YYYY'), 'Nagpur', 'MALE', 9321098765, '[email protected]', 'GHRA', 45)
INTO STUDENT VALUES (2121, 'Dev', 'Mishra', TO_DATE('13-AUG-2005', 'DD-MON-
YYYY'), 'Kanpur', 'MALE', 9786543210, '[email protected]', 'HBTU', 41)
INTO STUDENT VALUES (2122, 'Priya', 'Sahu', TO_DATE('17-SEP-2006', 'DD-MON-
YYYY'), 'Gurgaon', 'FEMALE', 9898765432, '[email protected]', 'DCRUST', 42)
INTO STUDENT VALUES (2123, 'Ayaan', 'Ali', TO_DATE('05-JAN-2007', 'DD-MON-YYYY'),
'Agra', 'MALE', 9865432101, '[email protected]', 'UAG', 43)
INTO STUDENT VALUES (2124, 'Sofia', 'Choudhary', TO_DATE('29-MAR-2005', 'DD-
MON-YYYY'), 'Varanasi', 'FEMALE', 9123456780, '[email protected]', 'BHU',
44)
INTO STUDENT VALUES (2125, 'Tanvi', 'Kohli', TO_DATE('10-MAY-2007', 'DD-MON-
YYYY'), 'Raipur', 'FEMALE', 9221098765, '[email protected]', 'NITR', 45)
SELECT * FROM dual;

31
----3.Inserting 5 rows in Staff table-----

INSERT ALL
INTO Staff VALUES (121, 'Aditi', 'Sharma', '[email protected]', '7890123456',
'B.C.A', TO_DATE('2018-05-10', 'YYYY-MM-DD'), 5, 60000)
INTO Staff VALUES (122, 'Rahul', 'Verma', '[email protected]', '8901234567',
'M.C.A', TO_DATE('2017-03-15', 'YYYY-MM-DD'), 6, 65000)
INTO Staff VALUES (123, 'Sneha', 'Gupta', '[email protected]', '9123456789',
'M.Tech in I.T', TO_DATE('2019-07-25', 'YYYY-MM-DD'), 4, 75000)
INTO Staff VALUES (124, 'Karan', 'Singh', '[email protected]', '7987654321', 'B.E
in C.S.E', TO_DATE('2018-09-12', 'YYYY-MM-DD'), 5, 70000)
INTO Staff VALUES (125, 'Neha', 'Patel', '[email protected]', '8712345670', 'M.E in
C.S.E', TO_DATE('2017-11-05', 'YYYY-MM-DD'), 7, 80000)
SELECT * FROM DUAL;

----4.Inserting 5 rows in STF_CRS_ASS table----

INSERT ALL
INTO STF_CRS_ASS (Staff_id, Course_id) VALUES (121, 41)
INTO STF_CRS_ASS (Staff_id, Course_id) VALUES (122, 43)
INTO STF_CRS_ASS (Staff_id, Course_id) VALUES (123, 45)
INTO STF_CRS_ASS (Staff_id, Course_id) VALUES (124, 42)
INTO STF_CRS_ASS (Staff_id, Course_id) VALUES (125, 44)
SELECT * FROM dual;

----5.Inserting 15 rows in Staff_sal table-----

INSERT ALL
INTO Staff_sal VALUES (121, 'JUL', 22, 2, 60000, 54545, 1000000000000001)
INTO Staff_sal VALUES (122, 'JUL', 22, 1, 65000, 62045, 1000000000000002)
INTO Staff_sal VALUES (123, 'JUL', 22, 0, 75000, 75000, 1000000000000003)
INTO Staff_sal VALUES (124, 'JUL', 22, 2, 70000, 63636, 1000000000000004)
INTO Staff_sal VALUES (125, 'JUL', 22, 1, 80000, 76363, 1000000000000005)
INTO Staff_sal (VALUES (121, 'AUG', 23, 2, 60000, 54782, 1000000000000006)
INTO Staff_sal VALUES (122, 'AUG', 23, 1, 65000, 62173, 1000000000000007)
INTO Staff_sal VALUES (123, 'AUG', 23, 3, 75000, 65217, 1000000000000008)
INTO Staff_sal VALUES (124, 'AUG', 23, 2, 70000, 63913, 1000000000000009)
32
INTO Staff_sal VALUES (125, 'AUG', 23, 0, 80000, 80000, 1000000000000010)
INTO Staff_sal VALUES (121, 'SEP', 22, 1, 60000, 57272, 1000000000000011)
INTO Staff_sal VALUES (122, 'SEP', 22, 0, 65000, 65000, 1000000000000012)
INTO Staff_sal VALUES (123, 'SEP', 22, 3, 75000, 64772, 1000000000000013)
INTO Staff_sal VALUES (124, 'SEP', 22, 2, 70000, 63636, 1000000000000014)
INTO Staff_sal VALUES (125, 'SEP', 22, 1, 80000, 76364, 1000000000000015)
SELECT * FROM DUAL;

----6.Inserting 25 rows in Fees table-----

INSERT ALL
INTO Fees (Stud_id, Transaction_id, Course_id, Fees_paid, Payment_date) VALUES
(2101, 1001234567890123, 41, 5000, TO_DATE('01-JAN-2023', 'DD-MON-YYYY'))
INTO Fees (Stud_id, Transaction_id, Course_id, Fees_paid, Payment_date) VALUES
(2102, 1002345678901234, 42, 6000, TO_DATE('02-FEB-2023', 'DD-MON-YYYY'))
INTO Fees (Stud_id, Transaction_id, Course_id, Fees_paid, Payment_date) VALUES
(2103, 1003456789012345, 43, 7000, TO_DATE('03-MAR-2023', 'DD-MON-YYYY'))
INTO Fees (Stud_id, Transaction_id, Course_id, Fees_paid, Payment_date) VALUES
(2104, 1004567890123456, 44, 6500, TO_DATE('04-APR-2023', 'DD-MON-YYYY'))
INTO Fees (Stud_id, Transaction_id, Course_id, Fees_paid, Payment_date) VALUES
(2105, 1005678901234567, 45, 7000, TO_DATE('05-MAY-2023', 'DD-MON-YYYY'))
INTO Fees (Stud_id, Transaction_id, Course_id, Fees_paid, Payment_date) VALUES
(2106, 1006789012345678, 41, 5000, TO_DATE('06-JUN-2023', 'DD-MON-YYYY'))
INTO Fees (Stud_id, Transaction_id, Course_id, Fees_paid, Payment_date) VALUES
(2107, 1007890123456789, 42, 6000, TO_DATE('07-JUL-2023', 'DD-MON-YYYY'))
INTO Fees (Stud_id, Transaction_id, Course_id, Fees_paid, Payment_date) VALUES
(2108, 1008901234567890, 43, 7000, TO_DATE('08-AUG-2023', 'DD-MON-YYYY'))
INTO Fees (Stud_id, Transaction_id, Course_id, Fees_paid, Payment_date) VALUES
(2109, 1009012345678901, 44, 6500, TO_DATE('09-SEP-2023', 'DD-MON-YYYY'))
INTO Fees (Stud_id, Transaction_id, Course_id, Fees_paid, Payment_date) VALUES
(2110, 1010123456789012, 45, 7000, TO_DATE('10-OCT-2023', 'DD-MON-YYYY'))
INTO Fees (Stud_id, Transaction_id, Course_id, Fees_paid, Payment_date) VALUES
(2111, 1011234567890123, 41, 5000, TO_DATE('11-NOV-2023', 'DD-MON-YYYY'))
INTO Fees (Stud_id, Transaction_id, Course_id, Fees_paid, Payment_date) VALUES
(2112, 1012345678901234, 42, 6000, TO_DATE('12-DEC-2023', 'DD-MON-YYYY'))
INTO Fees (Stud_id, Transaction_id, Course_id, Fees_paid, Payment_date) VALUES
(2113, 1013456789012345, 43, 7000, TO_DATE('13-JAN-2023', 'DD-MON-YYYY'))
INTO Fees (Stud_id, Transaction_id, Course_id, Fees_paid, Payment_date) VALUES
33
(2114, 1014567890123456, 44, 6500, TO_DATE('14-FEB-2023', 'DD-MON-YYYY'))
INTO Fees (Stud_id, Transaction_id, Course_id, Fees_paid, Payment_date) VALUES
(2115, 1015678901234567, 45, 7000, TO_DATE('15-MAR-2023', 'DD-MON-YYYY'))
INTO Fees (Stud_id, Transaction_id, Course_id, Fees_paid, Payment_date) VALUES
(2116, 1016789012345678, 41, 5000, TO_DATE('16-APR-2023', 'DD-MON-YYYY'))
INTO Fees (Stud_id, Transaction_id, Course_id, Fees_paid, Payment_date) VALUES
(2117, 1017890123456789, 42, 6000, TO_DATE('17-MAY-2023', 'DD-MON-YYYY'))
INTO Fees (Stud_id, Transaction_id, Course_id, Fees_paid, Payment_date) VALUES
(2118, 1018901234567890, 43, 7000, TO_DATE('18-JUN-2023', 'DD-MON-YYYY'))
INTO Fees (Stud_id, Transaction_id, Course_id, Fees_paid, Payment_date) VALUES
(2119, 1019012345678901, 44, 6500, TO_DATE('19-JUL-2023', 'DD-MON-YYYY'))
INTO Fees (Stud_id, Transaction_id, Course_id, Fees_paid, Payment_date) VALUES
(2120, 1020123456789012, 45, 7000, TO_DATE('20-AUG-2023', 'DD-MON-YYYY'))
INTO Fees (Stud_id, Transaction_id, Course_id, Fees_paid, Payment_date) VALUES
(2121, 1021234567890123, 41, 5000, TO_DATE('21-SEP-2023', 'DD-MON-YYYY'))
INTO Fees (Stud_id, Transaction_id, Course_id, Fees_paid, Payment_date) VALUES
(2122, 1022345678901234, 42, 6000, TO_DATE('22-OCT-2023', 'DD-MON-YYYY'))
INTO Fees (Stud_id, Transaction_id, Course_id, Fees_paid, Payment_date) VALUES
(2123, 1023456789012345, 43, 7000, TO_DATE('23-NOV-2023', 'DD-MON-YYYY'))
INTO Fees (Stud_id, Transaction_id, Course_id, Fees_paid, Payment_date) VALUES
(2124, 1024567890123456, 44, 6500, TO_DATE('24-DEC-2023', 'DD-MON-YYYY'))
INTO Fees (Stud_id, Transaction_id, Course_id, Fees_paid, Payment_date) VALUES
(2125, 1025678901234567, 45, 7000, TO_DATE('25-JAN-2023', 'DD-MON-YYYY'))
SELECT * FROM dual;

----7.Inserting 5 rows in C table-----

INSERT ALL
INTO C VALUES (2101, 'Aarav', 'Sharma', 85, 90, 88, 263, 87.67, 'A')
INTO C VALUES (2106, 'Krishna', 'Iyer', 78, 82, 76, 236, 78.67, 'B')
INTO C VALUES (2111, 'Pooja', 'Gupta', 92, 88, 90, 270, 90.00, 'A')
INTO C VALUES (2116, 'Karan', 'Mehta', 65, 70, 68, 203, 57.67, 'C')
INTO C VALUES (2121, 'Dev', 'Mishra', 88, 84, 89, 261, 87.00, 'A')
SELECT * FROM dual;

34
----8.Inserting 5 rows in CPP table-----

INSERT ALL
INTO CPP VALUES (2102, 'Vivaan', 'Gupta', 78, 82, 75, 235, 78.33, 'B')
INTO CPP VALUES (2107, 'Nisha', 'Verma', 85, 79, 88, 252, 84.00, 'A')
INTO CPP VALUES (2112, 'Sai', 'Kumar', 70, 74, 80, 224, 74.67, 'B')
INTO CPP VALUES (2117, 'Ananya', 'Chowdhury', 90, 92, 88, 270, 90.00, 'A')
INTO CPP VALUES (2122, 'Priya', 'Sahu', 65, 70, 72, 207, 59.00, 'C')
SELECT * FROM dual;

----9.Inserting 5 rows in PYTHON table-----

INSERT ALL
INTO Python VALUES (2103, 'Anaya', 'Khan', 85, 78, 80, 243, 81.00, 'A')
INTO Python VALUES (2108, 'Arjun', 'Patel', 70, 75, 68, 213, 71.00, 'B')
INTO Python VALUES (2113, 'Tanya', 'Nair', 88, 90, 85, 263, 87.67, 'A')
INTO Python VALUES (2118, 'Rahul', 'Bhattacharya', 65, 60, 70, 195, 55.00, 'C')
INTO Python VALUES (2123, 'Ayaan', 'Ali', 72, 78, 76, 226, 75.33, 'B')
SELECT * FROM dual;

select * from Python;

----10.Inserting 5 rows in JAVA table-----

INSERT ALL
INTO Java VALUES (2104, 'Reyansh', 'Mehta', 85, 90, 78, 253, 84.33, 'A')
INTO Java VALUES (2109, 'Diya', 'Reddy', 70, 65, 80, 215, 71.67, 'B')
INTO Java VALUES (2114, 'Aditya', 'Srinivasan', 60, 75, 70, 205, 68.33, 'B')
INTO Java VALUES (2119, 'Siddhi', 'Iyer', 50, 45, 55, 150, 50.00, 'C')
INTO Java VALUES (2124, 'Sofia', 'Choudhary', 40, 30, 20, 90, 30.00, 'F')
SELECT * FROM dual;

select * from java;

35
----11.Inserting 5 rows in DBMS table-----

INSERT ALL
INTO DBMS VALUES (2105, 'Saanvi', 'Nair', 85, 90, 88, 263, 87.67, 'A')
INTO DBMS VALUES (2110, 'Rohan', 'Singh', 78, 81, 80, 239, 79.67, 'B')
INTO DBMS VALUES (2115, 'Nitya', 'Desai', 92, 95, 94, 281, 93.67, 'A')
INTO DBMS VALUES (2120, 'Rishabh', 'Jha', 74, 76, 70, 220, 53.33, 'C')
INTO DBMS VALUES (2125, 'Tanvi', 'Kohli', 89, 85, 88, 262, 87.33, 'A')
SELECT * FROM dual;

36
sQl coMMands on taBles
INSERT Statement:
INSERT INTO Fees (Stud_id, Transaction_id, Course_id, Fees_paid,
Payment_date)
VALUES (2101, 1001234567890123, 41, 5000, TO_DATE('01-JAN-
2023', 'DD-MON-YYYY'));
UPDATE Statement:
UPDATE Staff
SET Sal = 60000;
WHERE Staff_id =122;

DELETE Statement:
DELETE FROM Student
WHERE Stud_id=2128;

SELECT Statement (Various examples):


*Selecting Specific Column*
SELECT Course_name

FROM Course;

*Arithmetic Operations*
1. SELECT Stud_id, Course_id, Fees_paid * 1.18 AS Total_Fees
FROM Fees;
2. SELECT Stud_id, T1_marks + T2_marks + T3_marks AS Total_Marks
FROM CPP;
37
*Aggregate Functions*
1.SELECT AVG(sal) AS Avg_Salary
FROM Staff;
2. SELECT Course_id, COUNT(Stud_id) AS Total_Students
FROM STUDENT
GROUP BY Course_id;

*String Functions*
1.SELECT CONCAT(S_fname, ' ', S_lname) AS Full_Name
FROM STUDENT;
2. SELECT UPPER(City) AS Upper_City
FROM STUDENT;
3. SELECT SUBSTR(Staff_fname, 1, 3) AS Short_Name
FROM Staff;

*Using GROUP BY Clause*


1. SELECT Stud_id, AVG(T1_marks + T2_marks + T3_marks) AS
Avg_Marks
FROM Python
GROUP BY Stud_id;
2. SELECT Staff_id, COUNT(Course_id) AS Course_Count
FROM STF_CRS_ASS
GROUP BY Staff_id;

38
*Using HAVING Clause*
1.SELECT Course_id, COUNT(Stud_id) AS Student_Count
FROM STUDENT
GROUP BY Course_id
HAVING COUNT(Stud_id) > 5;
2. SELECT Staff_id, AVG(sal) AS Avg_Salary
FROM Staff_sal
GROUP BY Staff_id
HAVING AVG(sal) > 50000;

*Subqueries*
1.SELECT S_fname, S_Lname
FROM STUDENT
WHERE Course_id = (SELECT Course_id FROM COURSE WHERE
Course_name = 'Java');
2. SELECT Staff_id
FROM STF_CRS_ASS
GROUP BY Staff_id
HAVING COUNT(Course_id) > 2;

39
*Joins*
1.Inner Join: Get student details along with their course name.
SELECT S.Stud_id, S.S_fname, S.S_Lname, C.Course_name
FROM STUDENT S
INNER JOIN COURSE C ON S.Course_id = C.Course_id;

2.Left Join: List all courses and the students enrolled in them
SELECT C.Course_name, S.Stud_id, S.S_fname
FROM COURSE C
LEFT JOIN STUDENT S ON C.Course_id = S.Course_id;

3.Right Join: List all students with their course details


SELECT S.Stud_id, S.S_fname, S.S_Lname, C.Course_name
FROM STUDENT S
RIGHT JOIN COURSE C ON S.Course_id = C.Course_id;

4.Full Outer Join: List all students and all courses, with matching
data if present.
SELECT S.Stud_id, S.S_fname, C.Course_name
FROM STUDENT S
FULL OUTER JOIN COURSE C ON S.Course_id = C.Course_id;

5.Self Join: Find pairs of students from the same city.


SELECT A.Stud_id AS Student1, B.Stud_id AS Student2, A.City
FROM STUDENT A, STUDENT B
WHERE A.City = B.City AND A.Stud_id <> B.Stud_id;

40
*Set Operators*
1.UNION: List all unique student first names from both C and CPP
tables.
SELECT S_fname FROM C
UNION
SELECT S_fname FROM CPP;

2.UNION ALL: List all student first names from both C and CPP
tables.
SELECT S_fname FROM C
UNION ALL
SELECT S_fname FROM CPP;

3.INTERSECT: Find students who are enrolled in both Python and


Java.
SELECT Stud_id FROM Python
INTERSECT
SELECT Stud_id FROM Java;

4.MINUS: List students in DBMS but not in CPP.


SELECT Stud_id FROM DBMS
MINUS
SELECT Stud_id FROM CPP;

41
pl-sQl coMMands on taBles

<<<<<----TRIGGERS--->>>>>

------1. TRIGGER TO AVOID INSERTING MARKS GREATER THAN 100


IN C TABLE ------

CREATE TRIGGER TR_MARK1


AFTER INSERT OR UPDATE
ON C
FOR EACH ROW
BEGIN
IF :NEW.T1_MARKS>100 OR :NEW.T2_MARKS>100 OR
:NEW.T3_MARKS>100 THEN
RAISE_APPLICATION_ERROR(-20001, 'MARKS CANNOT BE GREATER
THAN 100');END IF;
END;

------2. TRIGGER TO AVOID INSERTING MARKS GREATER THAN 100


IN CPP TABLE ------

CREATE TRIGGER TR_MARK2


AFTER INSERT OR UPDATE
ON CPP
FOR EACH ROW
BEGIN
IF :NEW.T1_MARKS>100 OR :NEW.T2_MARKS>100 OR
:NEW.T3_MARKS>100 THEN
42
RAISE_APPLICATION_ERROR(-20001, 'MARKS CANNOT BE GREATER
THAN 100');END IF;
END;

------3. TRIGGER TO AVOID INSERTING MARKS GREATER THAN 100


IN PYTHON TABLE ------

CREATE TRIGGER TR_MARK3


AFTER INSERT OR UPDATE
ON JAVA
FOR EACH ROW
BEGIN
IF :NEW.T1_MARKS>100 OR :NEW.T2_MARKS>100 OR
:NEW.T3_MARKS>100 THEN
RAISE_APPLICATION_ERROR(-20001, 'MARKS CANNOT BE GREATER
THAN 100');END IF;
END;

------4. TRIGGER TO AVOID INSERTING MARKS GREATER THAN 100


IN JAVA TABLE ------

CREATE TRIGGER TR_MARK4


AFTER INSERT OR UPDATE
ON PYTHON
FOR EACH ROW
BEGIN
IF :NEW.T1_MARKS>100 OR :NEW.T2_MARKS>100 OR
:NEW.T3_MARKS>100 THEN
43
RAISE_APPLICATION_ERROR(-20001, 'MARKS CANNOT BE GREATER
THAN 100');
END IF;
END;

------5. TRIGGER TO AVOID INSERTING MARKS GREATER THAN 100


IN DBMS TABLE ------

CREATE TRIGGER TR_MARK5


AFTER INSERT OR UPDATE
ON DBMS
FOR EACH ROW
BEGIN
IF :NEW.T1_MARKS>100 OR :NEW.T2_MARKS>100 OR
:NEW.T3_MARKS>100 THEN
RAISE_APPLICATION_ERROR(-20001, 'MARKS CANNOT BE GREATER
THAN 100');
END IF;
END;

<<<<<----CURSOR--->>>>>

------1.CURSOR TO FETCH AND DISPLAY TOP 3 MOST EXPERIENCED


STAFF MEMBERS ------
DECLARE
CURSOR TOP_CUR IS
SELECT *
FROM (
SELECT *
44
FROM C
ORDER BY AVG_MARKS DESC
)
WHERE ROWNUM <= 3;
TOP_REC C%ROWTYPE;
BEGIN
OPEN TOP_CUR;
LOOP
FETCH TOP_CUR INTO TOP_REC;
EXIT WHEN TOP_CUR%NOTFOUND;
DBMS_OUTPUT.PUT_LINE('NAME: '||TOP_REC.S_FNAME || ' ' ||
TOP_REC.S_LNAME || ' AVERAGE OF MARKS:
'||TOP_REC.AVG_MARKS);
END LOOP;
CLOSE TOP_CUR;
END;

------2. CURSOR TO FETCH AND DISPLAY TOP 3 STUDENTS WITH


HIGHEST PERCENTAGE------
DECLARE
CURSOR TOP_CUR IS
SELECT *
FROM (
SELECT *
FROM C
ORDER BY Percentage DESC

45
)
WHERE ROWNUM <= 3;
TOP_REC C%ROWTYPE;
BEGIN
OPEN TOP_CUR;
LOOP
FETCH TOP_CUR INTO TOP_REC;
EXIT WHEN TOP_CUR%NOTFOUND;
DBMS_OUTPUT.PUT_LINE('NAME: '||TOP_REC.S_FNAME || ' ' ||
TOP_REC.S_LNAME || ' AVERAGE OF MARKS:
'||TOP_REC.Percentage);
END LOOP;
CLOSE TOP_CUR;
END;

<<<<<----SEQUENCE--->>>>>

----Sequence for stud_id of student Table----


CREATE SEQUENCE stud_id_seq
START with 2126
INCREMENT BY 1
NOCYCLE
NOCACHE;

46
<<<<<----PROCEDURE--->>>>>

------1. PROCEDURE TO DISPLAY STUDENT ID AND FEES PAID


ACCORDING TO USER ENTERED STUDENT ID ------

CREATE OR REPLACE PROCEDURE FEES1


(ST_ID NUMBER)
IS
SID NUMBER;
FEE_PAID NUMBER;
BEGIN
SELECT STUD_ID,FEES_PAID
INTO SID,FEE_PAID
FROM FEES
WHERE ST_ID=STUD_ID;
DBMS_OUTPUT.PUT_LINE('STUDENT ID: '|| SID||' FEES PAID:
'||FEE_PAID);
END;

DECLARE
SID NUMBER:= :SID;
BEGIN
FEES1(SID);
END;

------2.Procedure to insert a row in Student table------

CREATE OR REPLACE PROCEDURE insert_into_stud(


Sfn IN Student.s_fname%TYPE,
47
Sln IN Student.s_lname%TYPE,
DOB IN Student.dob%TYPE,
ci IN Student.city%TYPE,
gen IN Student.gender%TYPE,
pn IN Student.phone_no%TYPE,
em IN Student.email%TYPE,
cn IN Student.clg_name%TYPE,
cid IN Student.course_id%TYPE
) IS
BEGIN
INSERT INTO Student VALUES(stud_id_seq.NEXTVAL, Sfn, Sln,
DOB, ci, gen, pn, em, cn, cid);
DBMS_OUTPUT.PUT_LINE('1 row inserted');
END;

BEGIN
insert_into_stud(
Sfn => :sfn,
Sln => :sln,
DOB => :DOB,
ci => :ci,
gen => :gen,
pn => :pn,
em => :em,
cn => :cn,
cid => :cid
);
END;
48
<<<<<----FUNCTION--->>>>>

------1. FUNCTION TO DISPLAY AVERAGE MARKS OF STUDENT------


CREATE OR REPLACE FUNCTION AVG_MARKS1
(T1 NUMBER, T2 NUMBER, T3 NUMBER)
RETURN NUMBER
AS
AVG1 NUMBER(6,3); -- You can define precision and scale for the
variable here
BEGIN
AVG1 := (T1 + T2 + T3) / 3;
RETURN AVG1;
END;

DECLARE
AVG2 NUMBER;
T1_MARKS1 NUMBER;
T2_MARKS1 NUMBER;
T3_MARKS1 NUMBER;
ST_ID NUMBER;
BEGIN
ST_ID:= :ST_ID;
SELECT T1_MARKS, T2_MARKS, T3_MARKS
INTO T1_MARKS1, T2_MARKS1, T3_MARKS1
FROM C
WHERE STUD_ID = ST_ID;
AVG2 := AVG_MARKS1(T1_MARKS1, T2_MARKS1, T3_MARKS1);
DBMS_OUTPUT.PUT_LINE('Average Marks: ' || AVG2);
EXCEPTION
49
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('STUDENT ID DOES NOT EXIST');
END;

------2. FUNCTION TO DISPLAY PAID SALARY USING STAFF_ID AND


MONTH------
CREATE OR REPLACE FUNCTION calculate_paid_salary (
p_staff_id IN Staff_sal.Staff_id%TYPE,
p_month IN Staff_sal.Month%TYPE
) RETURN NUMBER IS
v_paid_salary Staff_sal.Paid_sal%TYPE;
BEGIN
SELECT Paid_sal INTO v_paid_salary
FROM Staff_sal
WHERE Staff_id = p_staff_id AND Month = p_month;
RETURN v_paid_salary;
END;

SELECT calculate_paid_salary(121, 'AUG') FROM dual;

<<<<<----EXCEPTIONS---->>>>
------1. PREDEFINED EXCEPTION FOR DISPLAYING INFORMATION
OF PARTICULAR STUDENT WITH STUDENT ID ------

DECLARE
STAFF_DATA STAFF%ROWTYPE;
STAFFID NUMBER:= :STAFFID;
BEGIN
50
SELECT *
INTO STAFF_DATA
FROM STAFF
WHERE STAFF_ID=STAFFID;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('STAFF ID DOES NOT EXIST');
END;

------2. USER DEFINED EXCEPTION WHEN UPDATE ON STUDENT


TABLE OF COURSE ID ------

DECLARE
ST_ID NUMBER(20);
C_ID NUMBER(20);
INVALID_ID EXCEPTION;
BEGIN
ST_ID:= :ST_ID;
C_ID:= :C_ID;
UPDATE STUDENT
SET COURSE_ID=C_ID
WHERE STUD_ID=ST_ID;
IF SQL%NOTFOUND THEN
RAISE INVALID_ID;
END IF;
EXCEPTION
WHEN INVALID_ID THEN
DBMS_OUTPUT.PUT_LINE('STUDENT ID DOES NOT EXIST');
END;
51
resources used

Software Used:-
Oracle 11g :-Oracle 11g is a version of Oracle's relational
database management system, designed to handle
large-scale data storage and retrieval. It supports
advanced features like automated storage management,
enhanced performance optimization, and data security,
making it suitable for enterprise applications. Oracle 11g
also offers tools for data recovery, partitioning, and
management, as well as improvements in data
warehousing and application development. Its robust
architecture and scalability make it widely used in
various industries for managing complex databases
efficiently.

Website Used:-

https://www.tutorialspoint.com/plsql/index.htm

https://www.geeksforgeeks.org/pl-sql-tutorial/

https://www.javatpoint.com/pl-sql-tutorial

https://boardmix.com/app/home (To create Er diagram)


52
conclusion

The Online Coaching Classes database is built to organize and


manage all the important information needed for running
online classes. It keeps track of student details, the courses
they’re taking, teacher information, class schedules, and
student grades. This system makes it easier for students and
teachers to connect, allows teachers to see how each student
is doing, and helps manage enrollments smoothly. Overall, this
database makes online learning easier to handle, more
accurate, and provides a better experience for both students
and teachers. This database reduces the need for physical
records and paperwork, lowering administrative costs. It
optimizes resource allocation and minimizes redundancy. With
the growing trend of online learning, this database is equipped
to support remote student registrations, attendance, and
virtual course management, aligning with modern educational
needs.

53

You might also like