0% found this document useful (0 votes)
62 views

P1 Datawarehouse Final

The document describes designing a database to store information about college staff, students, classes, subjects, and their relationships. Tables are created for teachers, classes, fees, students, subjects, assignments of teachers to classes, subjects studied by students, and teachers assigned to students. The tables are linked using primary and foreign keys. An entity relationship diagram and star schema are also included.

Uploaded by

Priyank Keni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views

P1 Datawarehouse Final

The document describes designing a database to store information about college staff, students, classes, subjects, and their relationships. Tables are created for teachers, classes, fees, students, subjects, assignments of teachers to classes, subjects studied by students, and teachers assigned to students. The tables are linked using primary and foreign keys. An entity relationship diagram and star schema are also included.

Uploaded by

Priyank Keni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 20

PRACTICAL NO:01

TITLE: College Database Management System.

GROUP MEMBERS:
AARTI BHOSALE
SHREYA ACHARYA
GLADYS D’SOUZA

PROBLEM STATEMENT:
Design a database to maintain information about College staff and students satisfying
following properties:
1. Staff will have their id, name and salary.
2. Students should have their name, id, class id, roll no. and address.
3. One contains which class teacher will be teaching and how many students in
that class.
4. Next will be containing fee information for student.
5. Various subjects that are given to student and which teacher teaches those
subjects.

TABLES:
Teacher
Class
Fees
Student
Subject
Assign
Given
Teaches

All tables should be linked by primary key and foreign key relation as follows:
1. Primary key T_ID of teacher table is a foreign key for Subject, teaches and
Assign.
2. Primary key S_ID of student table is a foreign key for given and teaches.
3. Primary key SUB_ID of subject table is a foreign key for given.
4. Primary key C_ID of class table is a foreign key for student and assign.
5. Primary key R_NO from fees table is the foreign key in student table.
ER-DIAGRAM:

DATABASE:

TEACHER TABLE

T_ID T_NAME SALARY


123 Maria 30000
143 John 50000
CLASS TABLE

C_ID
1a
1b
1c
2a
2b

FEES TABLE

R_NO AMOUNT
150 5000
255 5000
720 3000
690 2000
835 1500

STUDENT TABLE

S_ID S_NAME ADDRESS C_ID R_NO


101 Gladys Andheri 1a 150
102 Shadaab Malad 1b 255
103 Aarti Virar 1c 690
201 Shreya Andheri 2a 720
202 Shubham Virar 2b 835

SUBJECT TABLE

SUB_ID SUB_NAME T_ID


11 DWM 123
12 PDS 123
13 HMI 123
21 DF 143
22 SOAD 143
23 SE 143

ASSIGN TABLE

T_ID C_ID
123 1a
123 1b
123 1c
143 2a
143 2b
STUDIES TABLE

S_ID SUB_ID
101 11
101 12
101 13
102 11
102 12
102 13
103 11
103 12
103 13
201 21
201 22
201 23
202 21
202 22
202 23

TEACHES TABLE

t_id s_id
123 101
123 102
123 103
143 201
143 202

CREATING TABLES
TEACHER TABLE
SQL> create table teacher(t_idint,t_namevarchar(20),salary int, primary key(t_
id));

Table created.

SQL>desc teacher
Name Null? Type
----------------------------------------- -------- ----------------------------

T_ID NOT NULL NUMBER(38)


T_NAME VARCHAR2(20)
SALARY NUMBER(38)
SQL> select * from teacher;
t_idt_name salary
----------------------
123 Maria 30000
143 John 50000

CLASS TABLE
SQL> create table class(c_idvarchar(2),primary key(c_id));
Table created.

SQL>desc class
Name Null? Type
----------------------------------------- -------- ----------------------------
C_ID NOT NULL VARCHAR2(2)

SQL> select * from class;


C_
--
1a
1b
1c
2a
2b

FEES TABLE
SQL> create table fees(r_noint,amountint,primary key(r_no));
Table created.
SQL>desc fees
Name Null? Type
----------------------------------------- -------- ----------------------------

R_NO NOT NULL NUMBER(38)


AMOUNT NUMBER(38)

SQL> select * from fees;


R_NO AMOUNT
---------- ----------
150 5000
255 5000
690 1500
720 3000
835 3000
STUDENT TABLE
SQL> create table student(s_idint,s_namevarchar(20),address
varchar(20),c_idvarchar(2),r_noint,primary key(s_id),foreign key(c_id) references
class(c_id),foreign key(r_no) references fees(r_no));

Table created.

SQL>desc student
Name Null? Type
----------------------------------------- -------- ----------------------------

S_ID NOT NULL NUMBER(38)


S_NAME VARCHAR2(20)
ADDRESS VARCHAR2(20)
C_ID VARCHAR2(2)
R_NO NUMBER(38)

SQL> select * from student;

S_ID S_NAME ADDRESS C_ R_NO


---------- -------------------- -------------------- -- ----------
101 Gladys Andheri 1a 150
102 Shadaab Malad1b 255
103 Aarti Virar1c 690
201 Shreya Andheri2a 720
202 Shubham Virar2b 835

SUBJECT TABLE
SQL> create table subject(sub_idint,sub_namevarchar(20),t_idint,primary
key(sub_id),foreign key(t_id) references teacher(t_id));
Table created.

SQL>desc subject
Name Null? Type
----------------------------------------- -------- ----------------------------
SUB_ID NOT NULL NUMBER(38)
SUB_NAME VARCHAR2(20)
T_ID NUMBER(38)
SQL> select * from subject;

SUB_ID SUB_NAME T_ID


---------- -------------------- ----------
11 DWM 123
12 PDS 123
13 HMI 123
21 DF 143
22 SOAD 143
23 SE 143
6 rows selected.

ASSIGN TABLE
SQL> create table assign(t_idint,c_idvarchar(2),primary key(t_id,c_id),foreign
key(t_id) references teacher(t_id),foreign key(c_id) references class(c_id));

Table created.

SQL>desc assign
Name Null? Type
----------------------------------------- -------- ----------------------------

T_ID NOT NULL NUMBER(38)


C_ID NOT NULL VARCHAR2(2)

SQL> select * from assign;

T_ID C_
---------- --
123 1a
123 1b
123 1c
143 2a
143 2b

STUDIES TABLE
SQL> create table studies(s_idint, sub_idint,primary key(s_id,sub_id),foreign
key(s_id) references student(s_id),foreign key(sub_id) references subject(sub_id
));

Table created.

SQL>desc studies
Name Null? Type
----------------------------------------- -------- ----------------------------

S_ID NOT NULLNUMBER(38)


SUB_ID NOT NULL NUMBER(38)

SQL> select * from studies;

S_ID SUB_ID
---------- ----------
101 11
101 12
101 13
102 11
102 12
102 13
103 11
103 12
103 13
201 21
201 22
201 23
202 21
202 22
202 23

15 rows selected.

TEACHES TABLE
SQL> create table teaches(t_idint,s_idint,primary key(t_id,s_id), foreign key(
t_id) references teacher(t_id),foreign key(s_id) references student(s_id));

Table created.

SQL>desc teaches
Name Null? Type
----------------------------------------- -------- ----------------------------

T_ID NOT NULL NUMBER(38)


S_ID NOT NULLNUMBER(38)
SQL> select * from teaches;

T_ID S_ID
---------- ----------
123 101
123 102
123 103
143 201
143 202

SQL> commit;
Commit complete.

INFORMATION PACKAGE DIAGRAM:

Teacher Subject Student


t_id sub_id s_id
t_name sub_name s_name
salary address
c_id amount
r_no
Fact:number of students, filled seats, unfilled seats,
placements, fees paid, number of teachers.

Information Package Diagram: College management


STAR SCHEMA:
DATAWARE HOUSE:
TABLE TEACHER1
SQL> create table teacher1(t_idint,t_namevarchar(20),salary int,c_idvarchar(2),primary
key(t_id));
Table created.

SQL> insert into teacher1 values(123,'Maria',30000,'1a');


1 row created.
SQL> insert into teacher1 values(124,'John',50000,'1b');
1 row created.
SQL> insert into teacher1 values(125,'Sweedle',40000,'1c');
1 row created.
SQL> insert into teacher1 values(126,'Joshi',20000,'2a');
1 row created.
SQL> insert into teacher1 values(127,'Mahajan',55000,'2b');
1 row created.
SQL> insert into teacher1 values(128,'Shetty',60000,'2c');
1 row created.
SQL> insert into teacher1 values(129,'Shende',60000,'3a');
1 row created.
SQL> insert into teacher1 values(130,'Patil',65000,'3b');
1 row created.
SQL> insert into teacher1 values(131,'Bhosale',55000,'3c');
1 row created.
SQL> insert into teacher1 values(132,'Acharya',30000,'3d');
1 row created.
SQL> select * from teacher1;

T_ID T_NAME SALARY C_


---------- -------------------- ---------- --
123 Maria 30000 1a
124 John 50000 1b
125 Sweedle 40000 1c
126 Joshi 20000 2a
127 Mahajan55000 2b
128 Shetty 60000 2c
129 Shende 60000 3a
130 Patil 65000 3b
131 Bhosale 55000 3c
132 Acharya 30000 3d

10 rows selected.
TABLE SUBJECT1
SQL> create table subject1(sub_idint,sub_namevarchar(20),primary key(sub_id));
Table created.

SQL> insert into subject1 values(11,'DWM');


1 row created.
SQL> insert into subject1 values(12,'PDS');
1 row created.
SQL> insert into subject1 values(13,'HMI');
1 row created.
SQL> insert into subject1 values(21,'DF');
1 row created.
SQL> insert into subject1 values(22,'SOAD');
1 row created.
SQL> insert into subject1 values(23,'AI');
1 row created.
SQL> insert into subject1 values(31,'SC');
1 row created.
SQL> insert into subject1 values(32,'OS');
1 row created.
SQL> insert into subject1 values(33,'TCS');
1 row created.
SQL> insert into subject1 values(41,'MATHS');
1 row created.
SQL>select * from subject1;

SUB_ID SUB_NAME
---------- --------------------
11 DWM
12 PDS
13 HMI
21 DF
22 SOAD
23 AI
31 SC
32 OS
33 TCS
41 MATHS

10 rows selected.

TABLE STUD1
SQL> create table stud1(s_idint,s_namevarchar(20),address
varchar(20),r_noint,amountint,totalint, primary key(s_id));
Table created.
SQL> insert into stud1 values(101,'Gladys','Andheri',150,5000,95);
1 row created.
SQL> insert into stud1 values(102,'Shadaab','Malad',255,5000,92);
1 row created.
SQL> insert into stud1 values(103,'Aarti','Virar',690,5000,96);
1 row created.
SQL> insert into stud1 values(201,'Shreya','Andheri',720,5000,96);
1 row created.
SQL> insert into stud1 values(202,'Shubham','Virar',835,5000,77);
1 row created.
SQL> insert into stud1 values(301,'Teju','Miraroad',250,5000,75);
1 row created.
SQL> insert into stud1 values(302,'Dhwani','Dahisar',355,5000,85);
1 row created.
SQL> insert into stud1 values(303,'Jagrut','Boisar',790,5000,66);
1 row created.
SQL> insert into stud1 values(401,'Nilam','Miraroad',920,5000,55);
1 row created.
SQL> insert into stud1 values(402,'Sanjay','Dadar',825,5000,72);
1 row created.
SQL> select * from stud1;

S_ID S_NAME ADDRESS R_NO AMOUNT TOTAL


---------- -------------------- -------------------- ---------- ---------- ----------
101 Gladys Andheri 150 5000 95
102 Shadaab Malad 255 5000 92
103 Aarti Virar 690 5000 96
201 Shreya Andheri 720 5000 96
202 Shubham Virar 835 5000 77
301 Teju Miraroad 250 5000 75
302 Dhwani Dahisar 355 5000 85
303 Jagrut Boisar 790 5000 66
401 Nilam Miraroad 920 5000 55
402 Sanjay Dadar 825 5000 72

10 rows selected.

FACT TABLE
COLLEGEMGT TABLE /*3 rows taken*/

SQL> create table collegemgt(t_idint,sub_idint,s_idint,marksint,foreign key(t_id)


references teacher1(t_id),foreign key(sub_id) references subject1(sub_id),foreign
key(s_id) references stud1(s_id));

Table created.
SQL> insert into collegemgt values(123,11,102,50);
1 row created.
SQL> insert into collegemgt values(123,11,103,60);
1 row created.
SQL> insert into collegemgt values(123,12,101,72);
1 row created.
SQL> insert into collegemgt values(123,12,102,80);
1 row created.
SQL> insert into collegemgt values(123,12,103,32);
1 row created.
SQL> insert into collegemgt values(123,13,101,65);
1 row created.
SQL> insert into collegemgt values(123,13,102,44);
1 row created.
SQL> insert into collegemgt values(123,13,103,55);
1 row created.
SQL> insert into collegemgt values(124,11,101,62);
1 row created.
SQL> insert into collegemgt values(124,11,102,39);
1 row created.
SQL> insert into collegemgt values(124,11,103,40);
1 row created.
SQL> insert into collegemgt values(124,12,101,49);
1 row created.
SQL> insert into collegemgt values(124,12,102,56);
1 row created.
SQL> insert into collegemgt values(124,12,103,65);
1 row created.
SQL> insert into collegemgt values(124,13,101,77);
1 row created.
SQL> insert into collegemgt values(124,13,102,62);
1 row created.
SQL> insert into collegemgt values(124,13,103,79);
1 row created.
SQL> insert into collegemgt values(125,11,101,88);
1 row created.
SQL> insert into collegemgt values(125,11,102,84);
1 row created.
SQL> insert into collegemgt values(125,11,103,70);
1 row created.
SQL> insert into collegemgt values(125,12,101,74);
1 row created.
SQL> insert into collegemgt values(125,12,102,59);
1 row created.
SQL> insert into collegemgt values(125,12,103,49);
1 row created.
SQL> insert into collegemgt values(125,13,101,50);
1 row created.
SQL> insert into collegemgt values(125,13,102,56);
1 row created.
SQL> insert into collegemgt values(125,13,103,82);
1 row created.
SQL> select * from collegemgt;

T_ID SUB_ID S_ID MARKS


---------- ---------- ---------- ----------
123 11 102 50
123 11 103 60
123 12 101 72
123 12 102 80
123 12 103 32
123 13 101 65
123 13 102 44
123 13 103 55
124 11 101 62
124 11 102 39
124 11 103 40
124 12 101 49
124 12 102 56
124 12 103 65
124 13 101 77
124 13 102 62
124 13 103 79
125 11 101 88
125 11 102 84
125 11 103 70
125 12 101 74
125 12 102 59
125 12 103 49
125 13 101 50
125 13 102 56
125 13 103 82

26 rows selected.
OLAP QUERIES:

RANK

Q] Rank the students according to the total marks obtained. The student with
highest total must have the highest rank. Display name and rank.
SQL> select s_name,rank() over(order by total desc)RNK from stud1;
S_NAME RNK
-------------------- ----------
Aarti 1
Shreya 1
Gladys 3
Shadaab 4
Dhwani 5
Shubham 6
Teju 7
Sanjay 8
Jagrut 9
Nilam 10

10 rows selected.

Q] Give the rank of the student according to the places they live. The highest
total student should get highest rank than the other student of the same
address.
SQL> select s_id,s_name,address,rank() over(partition by address order by totaldesc)
RNK from stud1;

S_ID S_NAME ADDRESS RNK


---- -------------- -------------------- ----------
201 Shreya Andheri 1
101 Gladys Andheri 2
303 Jagrut Boisar 1
402 Sanjay Dadar 1
302 Dhwani Dahisar 1
102 Shadaab Malad 1
301 Teju Miraroad 1
401 Nilam Miraroad 2
103 Aarti Virar 1
202 Shubham Virar 2

10 rows selected.
ROLLUP

Q] Display the marks given by a teacher toa student in a particular subject.


Display total of the particular subject thought by the teacher also display total
sum of marks obtained by the teacher for the entire subject she teaches.
SQL> select t_id,sub_id,s_id,sum(marks)
2 fromcollegemgt
3 group by rollup(t_id,sub_id,s_id);

T_ID SUB_ID S_ID SUM(MARKS)


---------- ---------- ---------- ----------
123 11 102 50
123 11 103 60
123 11 110
123 12 101 72
123 12 102 80
123 12 103 32
123 12 184
123 13 101 65
123 13 102 44
123 13 103 55
123 13 164
123 458
124 11 101 62
124 11 102 39
124 11 103 40
124 11 141
124 12 101 49
124 12 102 56
124 12 103 65
124 12 170
124 13 101 77
124 13 102 62
124 13 103 79
124 13 218
124 529
125 11 101 88
125 11 102 84
125 11 103 70
125 11 242
125 12 101 74
125 12 102 59
125 12 103 49
125 12 182
125 13 101 50
125 13 102 56
125 13 103 82
125 13 188
125 612
1599
39 rows selected.

CUBE

Q] Display the marks given by a teacher toa student in a particular subject.


Display total of the particular subject thought by the teacher also display total
sum of marks obtained by the teacher for the entire subject she teaches.
SQL> select t_id,sub_id,s_id,sum(marks)
2 fromcollegemgt
3 group by cube(t_id,sub_id,s_id);

T_ID SUB_ID S_ID SUM(MARKS)


---------- ---------- ---------- ----------
1599
101 537
102 530
103 532
11 493
11 101 150
11 102 173
11 103 170
12 536
12 101 195
12 102 195
12 103 146
13 570
13 101 192
13 102 162
13 103 216
123 458
123 101 137
123 102 174
123 103 147
123 11 110
123 11 102 50
123 11 103 60
123 12 184
123 12 101 72
123 12 102 80
123 12 103 32
123 13 164
123 13 101 65
123 13 102 44
123 13 103 55
124 529
124 101 188
124 102 157
124 103 184
124 11 141
124 11 101 62
124 11 102 39
124 11 103 40
124 12 170
124 12 101 49
124 12 102 56
124 12 103 65
124 13 218
124 13 101 77
124 13 102 62
124 13 103 79
125 612
125 101 212
125 102 199
125 103 201
125 11 242
125 11 101 88
125 11 102 84
125 11 103 70
125 12 182
125 12 101 74
125 12 102 59
125 12 103 49
125 13 188
125 13 101 50
125 13 102 56
125 13 103 82

63 rows selected.

GROUPING SETS

Q] Provide sum of marks for teacher id, subject id, and student id. Group them
according to the similar value from the rows.
SQL> select t_id,sub_id,s_id,sum(marks)
2 fromcollegemgt
3 group by grouping sets(t_id,sub_id,s_id);

T_ID SUB_ID S_ID SUM(MARKS)


---------- ---------- ---------- ----------
123 458
125 612
124 529
11 493
13 570
12 536
102 530
101 537
103 532

9 rows selected.

CONCLUSION:

From this experiment we have learnt the difference between ER and dimensional
modeling, also to draw information package diagram. We have created a database
based on data warehouse in which we have created star schema, dimensional tables,
fact table considering the primary key of all dimension tables. Performed various
database operations on the tables. Executed OLAP queries on the data warehouse
tables.

You might also like