The document outlines the creation and management of a database for a course management system, including tables for students, teachers, courses, and scores. It includes SQL commands for inserting data, creating views, and defining procedures and functions for various operations. Additionally, it demonstrates the use of foreign keys for relationships between tables and the creation of an index on teacher salaries.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
2 views4 pages
Dataproject
The document outlines the creation and management of a database for a course management system, including tables for students, teachers, courses, and scores. It includes SQL commands for inserting data, creating views, and defining procedures and functions for various operations. Additionally, it demonstrates the use of foreign keys for relationships between tables and the creation of an index on teacher salaries.
from student , teacher , get_course , score , course where student.s_id = get_course.s_id and teacher.t_id = get_course.t_id and course.c_id = get_course.c_id and get_course.g_id = score.g_c;
create view select_all as
select student.s_name ,teacher.t_naw , course.c_name, score.grade from student , teacher , get_course , score , course where student.s_id = get_course.s_id and teacher.t_id = get_course.t_id and course.c_id = get_course.c_id and get_course.g_id = score.g_c;
select *from select_all;
--< procedure
CREATE OR REPLACE PROCEDURE count_s IS
output NUMBER; BEGIN SELECT COUNT(student.s_id) INTO output FROM student JOIN get_course ON student.s_id = get_course.s_id;
DBMS_OUTPUT.PUT_LINE('Count of students: ' || output);
END; /
exec count_s;
CREATE OR REPLACE PROCEDURE insert_g_c (
id IN NUMBER, s_id IN NUMBER, t_id IN NUMBER, c_id IN NUMBER ) AS BEGIN INSERT INTO get_course (g_id, s_id, t_id, c_id) VALUES (id, s_id, t_id, c_id); END; /
exec insert_g_c 402,100,202,302;
CREATE OR REPLACE PROCEDURE get_course_by_name (
p_name IN NUMBER ) AS output VARCHAR2(255); BEGIN SELECT c.c_name INTO output FROM course c JOIN get_course g ON c.c_id = g.c_id JOIN student s ON s.s_id = g.s_id WHERE g.s_id = p_name;
DBMS_OUTPUT.PUT_LINE('Course Name: ' || output);
EXCEPTION WHEN NO_DATA_FOUND THEN DBMS_OUTPUT.PUT_LINE('No course found for the given student ID.'); WHEN OTHERS THEN DBMS_OUTPUT.PUT_LINE('An error occurred: ' || SQLERRM); END; /
exec get_course_by_name 101 ;
--< founction
CREATE OR REPLACE FUNCTION joinn(
s_name IN VARCHAR2, s_age IN VARCHAR2 ) RETURN VARCHAR2 AS result VARCHAR2(150); BEGIN result := s_name || ' ' || s_age; RETURN result; END; /
select dbo.joinn (s_name,s_age) from student ;
--< index CREATE INDEX inndex_teacher_salary ON teacher (t_salary);