0% 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.

Uploaded by

hamafarhad185
Copyright
© © All Rights Reserved
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% 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.

Uploaded by

hamafarhad185
Copyright
© © All Rights Reserved
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
You are on page 1/ 4

create database course;

use course;

create table student (


s_id int primary key,
s_name varchar(30),
s_age int,
s_phone varchar(30),
s_email varchar(70),
s_pass_word varchar(16)
);

insert into student


values(100,'karzan',25,'07701234567','[email protected]','12345678');

create table teacher (


t_id int primary key ,
t_naw varchar(30),
t_age int,
t_phone varchar(30),
t_email varchar(70),
t_pass_word varchar(16),
t_salary int
);

insert into teacher


values(200,'wrya',40,'07704567474','[email protected]','79797979',500)
,
(201,'saman',45,'0776656565','[email protected]','60606060',450)
,
(202,'barham',22,'07708796969','[email protected]','45454545',1000);
insert into teacher
values(203,'nasrin',45,'07709876545','[email protected]','11111111',2000);

create table course (


c_id int primary key,
c_name varchar(30),
c_price int,
dd date,

);

insert into course values(300,'chnin','1000','10/10/2022')


,(301,'english','begginer',100,'10/10/2022')
,(302,'arabic','begginer',250,'12/11/2018');

create table get_course(


g_id int primary key ,
s_id int,
t_id int,
c_id int,
foreign key(s_id) references student(s_id),
foreign key(t_id) references teacher(t_id),
foreign key(c_id) references course(c_id));

insert into get_course values(400,102,203,300),(401,101,200,302);

select *from get_course

create table score(


g_c int,
grade float,
foreign key (g_c) references get_course(g_id));

insert into score values(400,100),(401,99);


insert into score values (402,65);
select *from score

create table matrial (


m_id int primary key,
f_need varchar(255),
s_need varchar(255),
c_id int,
foreign key (c_id) references course(c_id)
);

insert into matrial values(500,'qwlap','shlila',300),(501,'qalam','kteb',301);

--< view

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;

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);

execute sp_helpindex teacher;


select *from teacher;

You might also like