Вы находитесь на странице: 1из 11

Student Attendance

System

Rajarsi Chattopadhyay
CSE 3rd year Sec A
Roll 67
Date_of_Admission
ER DIAGRAM
Year Sub_name SubjectId
ENNO Name

Year

Section
Student Studies Subject
Stream
Stream

Taught_By Has
Phone
Teaches Sub3ID
T2ID
TID
T3ID Sub2ID
Name
Routine
Follows
Sub1ID
Teacher
Stream
Section
DAY
Phone Updates
Stream
Year

Sal

Hiredate T1ID
Attendance_sheet

ENNO
SubStatus

Date SubId
Table Schema
Studentinfo
Name Null? Type

----------------------------------------- -------- --------------------------

ENNO NOT NULL VARCHAR2(10)

NAME VARCHAR2(30)

STREAM VARCHAR2(10)

YEAR NUMBER(2)

PHONE VARCHAR2(12)

SECTION VARCHAR2(3)

DATE_OF_ADMISSION DATE

Teacherinfo
Name Null? Type

----------------------------------------- -------- ---------------------------

TID NOT NULL VARCHAR2(10)

NAME VARCHAR2(30)

HIREDATE DATE

SAL NUMBER(9,2)

PHONE VARCHAR2(12)

STREAM VARCHAR2(10)

Routine
Name Null? Type
----------------------------------------- -------- ------------------

YEAR NOT NULL NUMBER(2)

STREAM NOT NULL VARCHAR2(10)

SECTION NOT NULL VARCHAR2(3)

DAY NOT NULL VARCHAR2(10)

SUB1ID VARCHAR2(10)

T1ID VARCHAR2(10)

SUB2ID VARCHAR2(10)

T2ID VARCHAR2(10)

SUB3ID VARCHAR2(10)

T3ID VARCHAR2(10)

Subject
Name Null? Type

----------------------------------------- -------- ---------------------

SUBJECTID NOT NULL VARCHAR2(10)

SUB_NAME VARCHAR2(20)

STREAM VARCHAR2(10)

YEAR NUMBER(2)

Attendance_sheet
Name Null? Type

----------------------------------------- -------- -----------------------

ENNO NOT NULL VARCHAR2(10)


DATE1 NOT NULL DATE

SUBID NOT NULL VARCHAR2(10)


SUBSTATUS NUMBER(1)

Table Scripts With Constraints


Studentinfo
create table Studentinfo

(Enno varchar2(10),

name varchar2(30),

stream varchar2(10),

year number(2),

phone varchar2(12),

section varchar2(3),

date_of_admission date

);

alter table studentinfo add constraint studentinfo_pk primary key(enno);

Subject
create table subject

(subjectid varchar2(10),

sub_name varchar2(20),

stream varchar2(10),

year number(2)

);

alter table subject add constraint subject_pk primary key(subjectid);

Teacherinfo
create table teacherinfo

(
tid varchar2(10),

name varchar2(30),

hiredate date,

sal number(9,2),

phone varchar2(12),

stream varchar2(10)

);

alter table teacherinfo add constraint teacherinfo_pk primary key(tid);

Routine
create table routine

(year number(2),

stream varchar2(10),

section varchar2(3),

day varchar2(10),

sub1id varchar2(10),

t1id varchar2(10),

sub2id varchar2(10),

t2id varchar2(10),

sub3id varchar2(10),

t3id varchar2(10)

);

alter table routine add constraint routine_pk primary key(year,stream,section,day);

alter table routine add constraint rountines_fk1 foreign key (sub1id) references subject(subjectid);

alter table routine add constraint rountines_fk2 foreign key (sub2id) references subject(subjectid);

alter table routine add constraint rountines_fk3 foreign key (sub3id) references subject(subjectid);
alter table routine add constraint rountinet_fk4 foreign key (t1id) references teacherinfo(tid);

alter table routine add constraint rountinet_fk5 foreign key (t2id) references teacherinfo(tid);

alter table routine add constraint rountinet_fk6 foreign key (t3id) references teacherinfo(tid);

Attendance_sheet
create table attendance_sheet

(enno varchar2(10),

date1 Date,

subid varchar2(10),

substatus number(1)

);

alter table attendance_sheet add constraint attsheet_pk primary key(enno,date1,subid);

alter table attendance_sheet add constraint attendancesheet_fk1 Foreign Key (subid) references
subject(subjectid);

alter table attendance_sheet add constraint attendancesheet_fk4 Foreign Key (enno) references
studentinfo(enno);
Stored Procedures
Retrieve routine given year and section
create or replace procedure retrieve_routine(sec Routine.section%type,y number,st routine.stream
%type, routine OUT SYS_REFCURSOR ) as

begin

open routine for select day,sub1id,t1id,sub2id,t2id,sub3id,t3id from routine where stream=st and
section=sec and year=y;

end;

Retrieve teacher routine given teacher id

create or replace procedure teacher_routine(t teacherinfo.tid%type,res OUT SYS_REFCURSOR) as

s teacherinfo.stream%type;

d routine.day%type;

y number(2);

sec varchar(3);

s1 subject.subjectid%type;

s2 subject.subjectid%type;

s3 subject.subjectid%type;

t1 teacherinfo.tid%type;

t2 teacherinfo.tid%type;

t3 teacherinfo.tid%type;

cursor c_routine is

select day,year,section,sub1id,t1id,sub2id,t2id,sub3id,t3id from routine order by day;

begin
delete from teach_routine;

open c_routine;

loop

fetch c_routine into d,y,sec,s1,t1,s2,t2,s3,t3;

if(t1=t) then

insert into teach_routine values(d,1,y||'year Sec:'||sec||' Subject Code:'||s1);

end if;

if(t2=t) then

insert into teach_routine values(d,2,y||'year Sec:'||sec||' Subject Code:'||s2);

end if;

if(t3=t) then

insert into teach_routine values(d,3,y||'year Sec:'||sec||' Subject Code:'||s3);

end if;

exit when c_routine%notfound;

end loop;

close C_routine;

open res for select * from teach_routine;

end;

Retrieve attendance of a subject given enrollment no and subjectid


create or replace procedure stu_attendance(sid subject.subjectid%type,e studentinfo.enno%type,res
OUT SYS_REFCURSOR) as

tc number(3);

ac number(3);

a number(5,2);

cursor c_sid is
select substatus from attendance_sheet where subid=sid and enno=e;

begin

tc:= 0;

ac:= 0;

open c_sid;

loop

fetch c_sid into a;

exit when c_sid%notfound;

tc:= tc +1;

ac:=ac+a;

end loop;

close c_sid;

if(tc=0)

then

a:=0;

else

a:= ac/tc*100;

end if;

open res for select tc,ac,a from dual;

end;

Вам также может понравиться