VOIP Project: Database implementation - Part 3

After creating the database model as shown in the previos post VOIP Project: Database modeling - Part 2, we will cover the implementation of that model in this part. On this project will be used a MySQL database. During this lesson we will demostrate the implementation on a MySQL database, which you can obtain by following the lesson Installing MySQL database, or you can create an account at db4free.net in order to have a MySQL database online.

First step after logging into the phpMyAdmin management site, as shown in VOIP Project: Database modeling - Part 2, will be the creation of the database. In the databases tab in the menu of the phpMyAdmin management site is selected the name of the database. During the development of the project the name of the database is set to voip_school_network. After the database is created, the next step that follows is the creation of the tables.

As seen in figure 1 of the lesson VOIP Project: Database modeling - Part 2, in order to supply all the data in a proper structure, this database will contain six tables. In order to properly organize the retrieving process of the data form the database and to pass the workload to the database, there is created a view named cit_view_consultation, a view containing information from three tables, cit_schedule, cit_subject and cit_consultation.

In order to create the tables in the phpMyAdmin management site, after clicking in the name of the database, in the create table session, must be provided the name of the table and the number of columns for each table that will be created. After clicking the go button a page where can be defined the name, type and other attributes for each column is opened. After filling the required information for each table as shown in the figure 1 of the database ERD in VOIP Project: Database modeling - Part 2 lesson, the table is created into the database.

In order to create the view, the proper query of the view must be executed in the SQL tab. In the session “Run SQL query/queries on database voip_school_network:” where a text area is provided must be written the following query:

Example code:
SELECT con.UserName, con.Subject_Id, sub.Name, sch.UserName as ProfessorUserName, con.Periodicity, con.Day, con.StartTime, con.EndTime from cit_consultation con join cit_subject sub on sub.Id = con.Subject_Id join cit_schedule sch on con.Subject_Id = sch.Subject_Id join cit_user usr on sch.UserName = usr.UserName where usr.Position = 'Professor';

and then the go button must be clicked. After the query execution, in the page that apears, in the query results options, create view option must be clicked. After the create view is clicked, in the popup window that appears, the name of the view must be defined, during the development of the project the given name of the view was cit_view_consultation and in the and go button must be clicked in order to create the view.

As it can be seen from the query shown in the previews paragraph, the view in the UserName column will contain the information from the cit_consultation table, and will be the username of the user for whom the consultation is registered.

The next column that the view will have, Subject_Id will have the id of the subject from the same table as the column UserName mentioned above. The Subject_Id will hold the value of the subject where a consultation will be held.

The username of the professor will be stored in the column ProfessorUserName of the view, which will take it values from the column UserName of the cit_schedule table. This column will hold the value of the UserName that teaches the subject with the specific given id.

The other three columns of the view, Day, StartTime and EndTime take their values from cit_consultation table. These three columns define the time when a consultation is held.

< Part 2: Database modeling Part 4: Understanding VOIP >

(please report broken link in the comment)

Comments

Popular posts from this blog

Free host and domain

C++ Beginner: Lesson 3 - Simple calculator

C++ Beginner: Lesson 4 - Tic Tac Toe game