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

Jview TechnicalNote en v1 SQLBasics

This document provides an introduction to SQL and accessing the Jigsaw production database. It describes how to connect to the Jigsaw server using Putty, and then access the PostgreSQL database called jmineops. It introduces basic SQL commands like SELECT and gives examples of querying data from tables in the MineOPS application database. The document is intended as an introductory guide for personnel to learn basic SQL.

Uploaded by

Jose Bezerra
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Jview TechnicalNote en v1 SQLBasics

This document provides an introduction to SQL and accessing the Jigsaw production database. It describes how to connect to the Jigsaw server using Putty, and then access the PostgreSQL database called jmineops. It introduces basic SQL commands like SELECT and gives examples of querying data from tables in the MineOPS application database. The document is intended as an introductory guide for personnel to learn basic SQL.

Uploaded by

Jose Bezerra
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

SQL Basics

Jigsaw Training Material


Newmont – Ghana Gold

December 2007
2
Table of Contents
1 Overview............................................................................................................ 1
1.1 Purpose ...................................................................................................... 1
1.2 Scope .........................................................................................................1
2 Jigsaw Server and Database Introduction ......................................................... 2
2.1 Server ......................................................................................................... 2
2.1.1 Accessing the Production Server......................................................... 2
2.2 Database .................................................................................................... 5
2.2.1 Accessing the Database ...................................................................... 5
3 SQL Commands ................................................................................................ 7
3.1 Before Beginning ........................................................................................ 7
3.1.1 Viewing Text ........................................................................................ 7
3.1.2 Copy and Paste Text ........................................................................... 8
3.1.3 Resize Window.................................................................................... 8
3.2 Basic Commands........................................................................................ 8
3.2.1 Main Menu........................................................................................... 9
3.2.2 View Column Names in a Table .......................................................... 9
3.2.3 SQL Help ........................................................................................... 10
3.2.4 Quit .................................................................................................... 11
3.3 The ‘select’ Command .............................................................................. 11
3.3.1 Select All Entries in a Table............................................................... 11
3.3.2 Select Specific Data .......................................................................... 12
3.3.3 Select Data in an Ordered Manner .................................................... 13
3.3.4 Select Data with Wildcards ................................................................ 13
3.4 A Few Shortcuts ....................................................................................... 14
3.4.1 Clear the Screen................................................................................ 14
3.4.2 Delete all Text After the Cursor ......................................................... 14
3.4.3 Delete all Text Before Cursor ............................................................ 14
3.4.4 View Old Commands ......................................................................... 14
3.4.5 Search Through Previously Typed Commands ................................. 15
4 Basic Database Layout .................................................................................... 17
4.1 A Sample Table ........................................................................................ 17
4.2 A Sample Relationship ............................................................................. 18
4.3 A Real Life Example ................................................................................. 18
4.3.1 Changing Records in MineOPS......................................................... 22
4.3.2 Viewing Relationships ....................................................................... 23

i
ii
1 Overview

1.1 Purpose
The purpose of this document is to provide an introduction to Structured Query Language
(SQL). This document will introduce basic SQL query commands, how to connect to the Jigsaw
server, and give a basic introduction to the Jigsaw production database (postgreSQL). This
document is not intended to be a stand alone user guide, but rather to give an introduction on
viewing and retrieving data generated from the MineOPS Application.

1.2 Scope
This document is intended to serve as an introductory guide to the SQL computer language,
intended for personnel involved with the MineOPS system. The intended users are:

• Dispatch Engineers
• Managers

The data contained on the Jigsaw Server can be viewed, modified, added to or deleted from
using standard SQL commands. Access to the database should be limited to those with the
correct privileges, as sever and critical damage can be inflicted upon the MineOPS Application
from the database.

This introduction to basic SQL commands is intended only for those new to SQL and databases
in general. This document is directed towards the user unfamiliar with SQL, and because of this,
there is no attempt to explain the more advanced features of the database in this document. At
other times, certain topics will be presented in a manner to simplify the explanation.

1
2 Jigsaw Server and Database Introduction
This section will quickly introduce the Jigsaw server, and the database contained on it, as well
as methods of accessing them. If you already have access to the jmineops database, you may
skip to Section 3.

2.1 Server
There are two Jigsaw Dell Poweredge 2950 Servers, named ngg01 and ngg02 respectively.
The first server contains the production database, and the second is the backup server. To view
information from the MineOPS Application, the production server, ngg01, should be used. The
next section details the steps used to access the server.

2.1.1 Accessing the Production Server


To access the server from a Windows computer, an application called Putty must be
downloaded to obtain a terminal on the server. If an application is already present on the
Windows machine, such as secure shell, it may be used instead.

Putty can be downloaded from the following site:

http://the.earth.li/~sgtatham/putty/latest/x86/putty.exe

Putty is an .exe file, and does not need to be installed. To access putty, simply double click the
icon from the download location, shown below.

2
A window asking permission to run will pop up. Select ‘Run’, as shown below.

The main Configuration window will appear. Enter the server I.P. address under the Host Name
field and select ‘Open’, as shown below. The server I.P. is: 10.223.102.10.

3
The application will now ask for the user name and password. Enter jigsaw as both the name
and password, shown below.

You know have a shell on the server, and should see the prompt shown below.

The server is running Ubuntu 7.04, and linux commands may be executed from this shell. The
production database, jmineops, will be introduced in the next section.

4
2.2 Database
The database behind the MineOps Application is located on the main Jigsaw server. The
database is a PostgreSQL database. PostgreSQL is an open source, object-relational database
management system. It accepts the standard SQL commands.

This document will introduce some of these SQL commands used to search and view data in
the PostgreSQL (PSQL) database. The next section demonstrates how to gain access to the
PSQL database from the ngg01 server.

2.2.1 Accessing the Database


This section will show hot to access the ngg01 server.

2.2.1.1 Naming Conventions


Before proceeding, the naming convention to be used in the rest of the document needs to be
discussed with regard to the command prompt, and commands to be issued. When a command
needs to entered, the document will first show the command prompt (which should be displayed
on the screen) and then the command prompt in bold (which must be entered by the user).
There are two command prompts that will be displayed, shown below.

Linux Prompt – The linux command prompt is:


ngg01:~$

A linux command will appear in this document as:

ngg01:~$ sample_linux_command
The line above tells the linux prompt to execute the command
sample_linux_command. The user must type the text – ‘sample_linux_command’
exactly as shown, since linux is case sensitive.

PSQL Prompt – The PSQL command prompt is:


jmineops=>

A PSQL command will appear in this document as:

jmineops=> sample_psql_command
The line above tells the postgres database prompt to execute the command
sample_psql_command. The user should type the text – ‘sample_psql_command’
exactly as shown. SQL commands may be entered as all lowercase characters,
or all uppercase characters. For simplicity, this document will use lowercase bold
text for the SQL commands, and the fields to be executed will be put in brackets
[].
5
A further example of this is shown below:

jmineops=> sql_command [text_field];

This convention will be looked at again in more detail in the next section.

2.2.1.2 Open the Database


To access the production database, enter the following command:

ngg01:~$ psql –U developer jmineops

Since this is the first real command executed, it will be broken down below in parts:

ngg01:~? – The linux command prompt, as described in the previous section.


psql – The linux command to open a PSQL database.
-U developer – specifies the user name as developer. This doesn’t change.
jmineops – The name of the PSQL databse to be opened. At the time of this
document, there is only one database present on the system. If
another database is added, the name jmineops would be changed to
reflect the name of the database to be opened.

If entered correctly, the following text will be displayed:

ngg01:~$ psql -U developer jmineops


Welcome to psql 8.2.4, the PostgreSQL interactive terminal.

Type: \copyright for distribution terms


\h for help with SQL commands
\? for help with psql commands
\g or terminate with semicolon to execute query
\q to quit

jmineops=>

The user is now connected to the database, and is ready to issue SQL commands to be
executed. The next section will describe these commands in detail.

6
3 SQL Commands
Once access to the PSQL database has been obtained, the user is ready to execute SQL
commands. SQL commands are recognized by many different databases. PSQL, the Jigsaw
database, is one of these. The following sections will break down common tasks used to access
and view data.

3.1 Before Beginning


Before introducing any commands, there are a couple of issues that arise for users new to
Postgres, or Linux in general.

3.1.1 Viewing Text


After selecting data from the command line, the contents of a table can be displayed in two
manners. If there is a small amount of data in the table, it will be displayed in completion, and
the command prompt will reappear ready for the next command.

if there is a large amount of data to display however, the contents will be brought up for the user
to scroll up and down to view, using the up and down arrows on the keyboard. To exit out of this
view of the data, the ‘q’ key must be pressed. A common mistake is to begin typing commands
before exiting the view. To fix this, any text accidentally entered must be deleted, and the ‘q’
button must be typed. An example of this is shown below.

The first screen shows a green box in the bottom left corner of the screen. This shows that the
window can be moved up and down, but is not ready to accept select statements until q has
been pressed.

7
The second screen shows a common error; the user is trying to enter a command, but the
window is still in view mode. The ‘q’ button must be pressed to clear this screen.

The command prompt, shown below, must be visible for the database to accept a command.

jmineops=>

3.1.2 Copy and Paste Text


The windows shortcuts, <CTRL>c to copy, and <CTRL>v to paste, work in some Linux
environments. They should be used with caution. In postgres, <CTRL>c will work to copy text,
but to paste the text, <CTRL>v will not work. Instead, the right click button on the mouse will
paste text.

3.1.3 Resize Window


It is common resize the window to a larger size to get all the text to appear on the screen at the
same time. Once you have entered the database however, you must exit and resize the window
before entering. The database will not acknowledge the window is bigger until this is done.

3.2 Basic Commands


The three sub-sections below show how to navigate the database. These commands do not
require a semicolon at the end of the command, like nearly every other SQL command. While
these three are not the only navigational commands, they are the main ones needed for the
typical user.
8
3.2.1 Main Menu
To view a list of the contents in the current database, type \h.

jmineops=> \d

This will list the items in the database, shown below:

All the tables are labeled under the Type column, and can be viewed with a ‘select’ statement.

3.2.2 View Column Names in a Table


To view a list of columns in a table, type:

jmineops=> \d table_name

9
The columns are displayed on the left side. This command is helpful for sorting data, when you
don’t remember the exact name of the columns in a table.

3.2.3 SQL Help


To view a list of all recognized SQL keywords, type.

jmineops=> \h

This will list the commands that can be entered, shown below:

10
The only command needed however, will be the ‘select’ statement. Section 4.3 deals with this
command.

3.2.4 Quit
To exit out of the PSQL database, type \q.

jmineops=> \q

3.3 The ‘select’ Command


The select statement is the command to view data and tables in the database. The following
sub-sections will introduce the select statement, and demonstrate how to use it.

3.3.1 Select All Entries in a Table


The format for using the select statement in its basic form is as follows:

Jmineops=> select * from table_name;

The part in bold is how every select statement must begin. In it’s simplest form, the table name
follows the bold section. Finally, all select statements must end with a semicolon.

Some simple examples of select statements are listed below.


11
Ex1: jmineops=> select * from equipment;
This example will select all records from the equipment table

Ex2: jmineops=> select * from devices;


This example will select all records from the devices table

Ex3: jmineops=> select * from enum_tables;


This example will select all records from the enum_tables table

Ex4: jmineops=> select * from workers;


This example will select all records from the workers table

Using the select statement in its basic form will display the whole contents of a table. At times
you will want to view a particular record, or set of records. The next sub-section examines this
topic.

3.3.2 Select Specific Data


The format for using the select statement in its basic form is as follows:

jmineops=> select * from table_name where column_name=column_field;

The first part of the statement is the same, we just expand it, starting with the where clause.
The where clause specifies that you only want to view part of a table, based on certain criteria.
After typing where, you must specify by which column you want to sort the data by. You can
choose any column to sort the data by.

After choosing the column, you must type the equal sign followed by the column field you wish
to view. To demonstrate this, we will use the workers table as an example.

Viewing the table using a simple select statement gives 298 results, which may be inconvenient
for searching through the data.

You can view the columns in the workers table by typing:

jmineops=> \d workers

Every column is a candidate for sorting. Some examples are listed below:

Ex1: jmineops=> select * from workers where id=7;


This example will select the worker with the id of 7

Ex2: jmineops=> select * from workers where last_name=’Duku’;


This example will select all workers with the last name Duku

Ex3: jmineops=> select * from workers where pay_number=21381;


This example will select the worker with a pay number of 21381

12
The three examples above were useful for selecting one item from a table. If you want to select
multiple data from the complete list, for example all workers from crew a, you use the same
principle.

Ex4: jmineops=> select * from workers where crew_id=1159;


This example will select all workers from the crew with and id of 1159 (Crew A)

3.3.3 Select Data in an Ordered Manner


We now know how to display a complete table, or part of a table. This section explains how to
display the table in an order desired by the user.

jmineops=> select * from table_name order by column_name;

This will order the data by the column chosen. Some examples are listed below.

Ex1: jmineops=> select * from workers order by first_name;


This example will display the workers table, displayed alphabetically, starting with
the letter ‘a’.

Ex2: jmineops=> select * from workers order by pay_number;


This example will display the workers table, displayed numerically, starting with
zero.

You can combine the where clause with the order by clause to achieve even more customized
data. In this case, the where should come before the order by, which appears at the end just
before the semicolon.

Ex3: jmineops=> select * from workers where crew_id=1159 order by pay_number;


This example will display the workers from crew A, displayed numerically, starting
with zero.

3.3.4 Select Data with Wildcards


There are times when you know what you are searching for, but can’t remember the exact
phrase you need. There are other times when you want to view data that is similar to other
entries, such as all items that begin with ‘HT’.

Wildcards can help with these situations. Wildcards are used to substitute for a string. For
example, all trucks in the equipment table begin with HT. Currently, the first truck is named
HT001 and the last is named HT024. Instead of viewing all 24 trucks individually, you can use a
wild crad to replace the numbers. The letters HT are common to all trucks, so the wild card
would represent the numbers of the trucks. The format is shown below:

jmineops=> select * from table_name where column like ‘known_text%’;

This will order the data by the column chosen. Some examples are listed below.
13
Ex1: jmineops=> select * from workers order by first_name;
This example will display the workers table, displayed alphabetically, starting with
the letter ‘a’.

Ex2: jmineops=> select * from workers order by pay_number;


This example will display the workers table, displayed numerically, starting with
zero.

You can combine the where clause with the order by clause to achieve even more customized
data. In this case, the where should come before the order by, which appears at the end just
before the semicolon.

Ex3: jmineops=> select * from workers where crew_id=1159 order by pay_number;


This example will display the workers from crew A, displayed numerically, starting
with zero.

3.4 A Few Shortcuts


This section will give a few shortcuts to make life easier. These commands should be entered
on the keyboard.

3.4.1 Clear the Screen


<CTRL>L

3.4.2 Delete all Text After the Cursor


<CTRL>k

This command will delete all the text typed under the cursor, and all text after the cursor, until
the end of the line is reached. All text before the cursor remains untouched.

3.4.3 Delete all Text Before Cursor


<CTRL>u

This command will delete all the text before the cursor. The character under the cursor
becomes the first character on the line. All text after the cursor remains untouched.

3.4.4 View Old Commands


You can cycle through old commands by pressing the up and down arrows on the keyboard

14
3.4.5 Search Through Previously Typed Commands
<CTRL>r

This command will search through all commands typed in the history of commands stored by
the database. After typing <CTRL>r, the prompt is ready for you to begin typing the command
you swish to search for.

Once you begin typing, the database will search for all commands typed that match exactly
what you have typed so far.

For example, if you want to find the command: ‘select * from enum_tables where id=924;’ from
history, you could use the <CTRL>r method.

We assume that the following 10 commands are in the history:

select * from reasons;


\d
select * from enum_tables where id=924;
select * from reasons where id=2;
update grades set material_id=1770,updated_at=getutcdate() where material_id=79;
select * from enum_tables;
select * from equipment where name='HT001';
\d shift_loads
insert into display_styles (updated_at,enum_id,display_config) values
(getutcdate(),1774,'_types={background=String};background="red"');
\q

To search for the desired command, you type <CTRL>r, and then begin typing select. After you
type ‘s’, you are eliminating all text in the history that does not begin with s. The commands in
history remaining are listed below:

select * from reasons


select * from enum_tables where id=924;
select * from reasons where id=2;
update grades set material_id=1770,updated_at=getutcdate() where material_id=79;
15
select * from enum_tables;
select * from equipment where name='HT001';

The most recent command in history that begins with s will appear, along with the text typed so
far.

You can continue typing, and eliminate more entries until you find your or selection, or continue
to press <CTRL>r to cycle through the remaining commands that match the text typed so far.
Once the command you want is found, press the right arrow key to select it.

16
4 Basic Database Layout
This section will briefly introduce how tables are layed out, and how relationships between
tables exist. If you have worked previously with relational databases, you may skip to Section 4.

4.1 A Sample Table


A relational database contains a set of tables that have values that may be used in other tables.
A basic table has s set of columns, which contain fields used as identifiers, and rows, which are
instances of the table. The columns in the tables cannot contain spaces. A blank sample table
named ‘example’ is outlined below:

jmineops=> select * from [example];


id | updated_at | field_1 | fileld_2 | filed_3_id
------+-----------------------+--------------+---------------+-----------------
(0 rows)

This example shows us several details about tables in Postgres.

The ‘id’ field is present in every table in the database. This number is unique for every
row, and is used to distinguish specific rows. Every row must contain an id.
The ‘updated_at’ filed is also present in every table. This filed is shown as a date n utc
time. The date is displayed first, followed by the time the record was updated at. A
sample date is: 2007-12-09 17:07:47. A ‘created_at’ filed may also be present in
addition, or replacement of the ‘updated_at’ field.
The ‘field_1’ and ‘field_2’ columns are informational fields specific to the table. They
may be numbers, text string or dates, depending on the table.
The ‘field_3_id’ column contains a numerical value that is being used by another
table.
After the last row, the number of rows is listed in parenthesis. In the sample table,
there are no rows, thus no data present.

If two rows were added to the table, it would be displayed as shown below:

jmineops=> select * from [example];


id | updated_at | field_1 | field_2 | filed_3_id
------+-------------------------------+---------------------+-------------------------+----------------
1 | 2007-12-09 17:07:47 | sample_text | sample_integer | 5
2 | 2007-12-09 17:07:49 | sample_text | | 8
(2 rows)

Some things to note about the updated table are shown below.

Row two has a column, ‘file_2’ without data. Some columns are mandatory, while
others may be left blank. This will be looked at more in detail in the next section.
The filed_3_id column contains two integers. This is the topic of the next sub-section.
Each row contains a unique record, and must contain a unique id.
17
4.2 A Sample Relationship
This section shows a typical relation ship found in the PSQL database. Using the sample table
from the previous section, we have the following.

jmineops=> select * from [example];


id | updated_at | field_1 | field_2 | fied_3_id
------+-------------------------------+---------------------+--------------------------+----------------
1 | 2007-12-09 17:07:47 | sample_text | sample_integer | 5
2 | 2007-12-09 17:07:49 | sample_text | | 8
(2 rows)

The ‘fied_3_id’ is referencing another table (or possibly a column in the same table). Frequently,
the table being references is actually a table name with the name of the column, minus the ‘_id’
part. Using this layout, we can look for the table called ‘field_3’.

jmineops=> select * from [field_3];


id | name | updated_at | field_a | field_2 | field_b_id
------+---------------+---------------------------------+--------------------+------------------------+------------------
1 | item_1 | 2007-12-09 17:08:47 | sample_text | sample_text | 1523
5 | item_5 | 2007-12-09 17:08:49 | sample_text | | 834
6 | item_6 | 2007-12-09 17:09:37 | sample_text | sample_text | 1533
8 | item_8 | 2007-12-09 17:09:49 | sample_text | | 1283
(4 rows)

Some things to note about table relationships are listed below:

Row 1 in the ‘example’ table is referring to ‘item_5’ in the ‘field_3’ table. The value 5 in
the sample table matches id 5 in the field_3 table, and thus its name is given as
‘item_5’. In the next Section, a real example from the MineOPS Application will be
used to clarify this relationship.
There are only four rows in the ‘field_3’ table. Rows 2,3,4 and 7 have been deleted (or
edited).
Even though both tables have a column field_2, they can have different data, and do
not relate to each other.
The ‘field_b_id’ column in the second table also references another table. Usually, id
columns with large values probably reference the ‘enum_tables’ table. .

4.3 A Real Life Example


To illustrate the relationship between tables, and the relationship between the MineOPS
Application and the PSQL database, an example will be shown below using real data.

18
The Equipment Screen from the MineOPS Application is shown below.

19
Selecting EX001, the following screen is displayed.

The following fields are present:

Equipment: Specifies which piece of equipment to view


Class: The type of equipment the item belongs to, predefined by Jigsaw
Status: The major status record (Down, Delay, Standby, Maintenance)
STATUS: The specific reason the equipment has for being in its’ state
Operator: Who is logged in to the equipment
Location: Where the equipment is currently located
Equipment Type: The type of equipment the item is
Deleted At: The date and time the item was deleted from the database, if applicable

The relationship between the office application and the database, as well as the effect of
changing the fields in MineOPS will be examined.

To begin, we will look at the equipment table in the database.

20
id: 30 – The unique row identifier for excavator EX001
type: Shovel – The class the equipment belongs to, predefined by Jigsaw
name: EX001 – The name of the equipment record
created_at: 2007-07-27 17:22:32 - The date and time the record was created at
updated_at: 2007-07-27 17:22:32 - The date and time the record was created at
deleted_at: The date and time the item was deleted from the database, if applicable
revision: Unused
device_id: 40 – References the fortieth row in the devices table
status_id: 1327 – References the entry in the enum_tables table with the id of 1327
reason_id: 2 – References the second row of the reasons table
lineup_status_id: Unused
equipment_type_id: 1055 - References the entry in the enum_tables table with the id of 1055
activity_id: 924 - References the entry in the enum_tables table with the id of 924
activity_start: 2007-12-10 17:34:36 – The date and time the current activity began
size: Unused
tiedown_id: Unused
unit_id: Unused
length: Unused
height: Unused
project_id: 1 – References the first row in the projects table
time_late: Unused
prestart_check: Unused
warnings: Unused

21
4.3.1 Changing Records in MineOPS
To switch the view in MineOPS to view another piece of equipment, you simply click the mouse.
An example of this is shown below, switching from EX001 to HT001.

This simple action accessed the database to retrieve the equipment record. The same action
could be completed in the database with the following command:

jmineops=> select * from equipment where name='HT001';

22
Making the change in MineOPS has the effect of changing rows in the database. In this case we
changed from row 30 (id=30) for EX001 to row 1 (id=1) for HT001.

To continue our example, we will switch back to EX001.

4.3.2 Viewing Relationships


Looking back to our original example, the record for HT001 has six columns that reference other
tables for EX001 currently being used.

4.3.2.1 device_id
The device_id column for EX001 contains a value of 40. To view the relationship, we need to
look at row forty of the devices table.

jmineops=> select * from devices where id=40;

23
The matching row in the devices table contains an entry for EX001. Looking at the columns, we
see that this table contains networking information for EX001. Changing the I.P. address in the
devices table, for example, will give the record in the equipment table a more complete picture
of EX001.

Both the equipment and devices table are used to set up the system correctly. The next section
shows a field that portrays the current information about a piece of equipment.

4.3.2.2 status_id
The status_id column for EX001 contains a value of 1327. This value references the
enum_tables table. We will look at that table, where the id is equal to 1327.

jmineops=> select * from enum_tables where id=1327;

24
This row shows that the record for EX001 in the equipment tables is referencing the row in the
enum_tables that contains a value for status of ready. This field is also being used in the
MineOPS Appplication, shown below:

Changing the status in the office application changes the id number the equipment table is
referencing from the enum_tables table.

4.3.2.3 reason_id
The reason_id column for EX001 contains a value of 2. To look at the relationship, we need to
look at row two of the reasons table.

jmineops=> select * from reasons where id=2;

25
This row shows that the record for EX001 in the equipment tables is referencing the second row
(id=2) in the reasons table. This field is also being used in the MineOPS Appplication, shown
below:

The display above uses two columns from the reasons table: the descrip, and code fields.
Changing the reason, or STATUS as it is referred to in the office software, changes the row of
the reasons table that EX001 is referencing in the equipment table.

4.3.2.4 equipment_type_id

26
The equipment_type_id column for EX001 contains a value of 1055. This value references the
enum_tables table. We will look at that table, where the id is equal to 1055.

jmineops=> select * from enum_tables where id=1055;

This row shows that the record for EX001 in the equipment tables is referencing the row in the
enum_tables that contains a value showing that the excavator is a Liebherr 994B. This field is
set when the equipment is added to the system, and does not need to changed once in the
system.

4.3.2.5 activity_id

The activity_id column for EX001 contains a value of 924. This value references the
enum_tables table. We will look at that table, where the id is equal to 924.

jmineops=> select * from reasons where id=924;

27
This row shows that the record for EX001 in the equipment tables is referencing the row in the
enum_tables that contains a value for an Activity of Waiting. This filed is constantly changing, as
the excavator moves from loading to waiting.

4.3.2.6 Other Fields in the Equipment Operations Screen


In the previous sub-sections, we examined the fields in the equipment table that reference other
tables. We used the Equipment Operations screen from the MineOPS Application as an
example of some of the fields being used from the database.

Not every field that contains a value in the equipment table is used in the Equipment Operations
Screen. In fact, only the following fields were used: Equipment (id), Class (type), Status
(status_id), STATUS (reason_id), Equipment type (equipment_type_id) and Deleted At
(deleted_at).

That leaves two fields in the Equipment Operations Screen that were not found in the
Equipment Table.

The first is the Operator field. This field is getting its’ information from the workers table. The
second field is the locations table. This information is collected from the Garmin GPS device
installed on the equipment in the field.

This shows that windows in the office software can contain values from multiple tables, and
finding these values in the database can be tedious.

28

You might also like