Motivations of why to Learn Databases

Before we define or explain what a database or even argue whether it is important for software development, let us ask the simple question: Can we create a software application without the use of a database system. To make it easier for you to answer such question, we take the simple example for an online phone directory which can be developed using a web scripting programming language such as PHP. The application is normally used by online visitors to search for phone numbers by typing the person surname as well as the address. The Figure below shows an example for the online phone directory provided by British Telecom to search for people phone numbers within the United Kingdom.
databases
The question that poses is where and how we can store the list of people’s names and their phone numbers permanently as well as retrieve them easily. In other words, how and where to store data such that it can be accessed by the web application. Trivially, the data would never be stored inside the application code as any modification needed for the data requires altering the code and therefore exacerbating compilation and deployment again which is an expensive and cumbersome process. The simplest solution would be to store data inside a normal text file whereby we format the data using a simple pre-defined structure. For instance, we store each record for a new person on a new line whilst the values for a record including name, surname and phone number should separated by a comma “,”. That’s what we call a CSV file “comma separated values” as illustrated in the following Figure which shows a simple architecture for the phone directory. There is a web interface written usually in HTML having a simple form to search for a person by name. Upon clicking the “search button” within the form, data is transmitted into the web server for processing. The server handles search and retrieval of data from the csv text file.
databases The following Listing  shows a simple code written in PHP programming language for a function that searches a text file named mydata.csv for a person record by a given name. The code contains less than 10 lines which is enough for a basic phone directory. The aim of this code is point to the simplicity of accessing and searching data files for developing the application.

<?php
function searchDirectory($name){
  $results=array();
  $people=file("mydata.csv");
  for($i=0;$i<count($people);$i++){
    $person=explode(",",strtolower($people[$i]));
    if(strpos($person[0],$name)!==FALSE)
      $results[]=$person;
  }
  return $results;
}
?>

The lines of codes are explained as follows:

  • Line 2: declaration of a function named searchDirectory that takes one parameter named $name$ which is submitted through the HTML form.
  • Line 3: Initialisation of an array named results for storing results.
  • Line 4: Opening the csv file mydata.csv into an array named people. Every line i.e. record  from the file is stored as an element within the array.
  • Line 5: For Loop to iterate through all records within the csv file.
  • Line 6: Splitting a single line which is a person record, into separate elements which are stored into an array named $person$.
  • Line 7: Comparing if the string name is contained with the first name of the person
  • Line 8: There is a match to be added inside the return results.

From the example being illustrated earlier, it becomes obvious that software applications can be developed without a fancy or advanced database system through the use of simple textual-based files. However, a number of basic questions and issues may arise when using such approach. For instance:

  • What if we want to enable concurrent or distributed management by different users connecting from remote different locations to the storage facility or files?
  • What about if we want to grant different access rights or roles to different users. For example, we grant read-only for guests and read-write for administrators.
  • What about the scalability and availability of the system when adding over a million of records where the performance of the search suffers greatly as it would scan a large number of lines within the file.

Further  and critical issues and challenges that needs to be addressed for software applications using flat-files for storage includes: File management, concurrency and multiple access, advanced search or operations, scalability, adding new  functionalities, integrity checking, maintenance and backup  and security.

Back to the first question of whether we can develop a software application without the use of an advanced database system. Yes, it can be done easily as shown earlier, but life would difficult and tough to address a large number of issues and functionalities for the system. This signifies the importance of using database systems and their critical role for software application as they were invented primarily to address the limitations encountered when using files as a direct storage facility. To further motivate you to learn databases in terms of money and job potentials, a comparative analysis for the average salary for different job roles within the United States of America, have showed that the average salary for an Oracle Database Administrator exceeds the average salary for Java Programmer, Research fellow and even a dentist as shown in the following Figure. The job role for a database administrator is usually to ensure the smooth functioning of an existing database system including maintenance and security hardening for the system. Other database related job roles include database designer, analyst and developer.
databases