P1 Datawarehouse Final
P1 Datawarehouse Final
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
C_ID
1a
1b
1c
2a
2b
FEES TABLE
R_NO AMOUNT
150 5000
255 5000
720 3000
690 2000
835 1500
STUDENT TABLE
SUBJECT TABLE
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
----------------------------------------- -------- ----------------------------
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)
FEES TABLE
SQL> create table fees(r_noint,amountint,primary key(r_no));
Table created.
SQL>desc fees
Name Null? Type
----------------------------------------- -------- ----------------------------
Table created.
SQL>desc student
Name Null? Type
----------------------------------------- -------- ----------------------------
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;
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 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 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 S_ID
---------- ----------
123 101
123 102
123 103
143 201
143 202
SQL> commit;
Commit complete.
10 rows selected.
TABLE SUBJECT1
SQL> create table subject1(sub_idint,sub_namevarchar(20),primary key(sub_id));
Table created.
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;
10 rows selected.
FACT TABLE
COLLEGEMGT TABLE /*3 rows taken*/
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;
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;
10 rows selected.
ROLLUP
CUBE
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);
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.