Table of Contents
The objective of this tutorial is to briefly describe the SQL commands and present examples that show how to use them.
The purpose of this tutorial is to introduce the reader to the basics of SQL (pronounced like the word sequel: see-quele). SQL stands for Structured Query Language In this tutorial, we will cover the following aspects of the SQL language:
SQL commands are used for accessing/manipulating data stored in Relational Database Management Systems (RDBMS). The SQL commands allows the means by which data can be
A database management system (DBMS) is a way to store data such that a computer program can easily retrieved it. Traditional databases are organized into rows of related data. These rows are also called records. A RDBMS is a type of database management system (DBMS) that stores data in related tables.
A table consists of two-dimensional sets of related data. In this case, a set is a row of data, where the data in that row is related. For example, a row might consist of the Visa account information for John Doe.
Each row consists of columns or fields, e.g., FirstName. A more generic representation of a table of rows and columns/fields might be shown like the following.
A primary key is a field/column or set of fields/columns that uniquely identifies the rest of the data in any given row. An example of a field that can be used that is unique is a social security number or an employee ID number. No two rows can have the same values for their primary key fields/columns.
A foreign key is a column in a table where that column is a primary key of another table, which means that any data in a foreign key column must have corresponding data in the other table where that column is the primary key. A foreign key field is a field that links one table to another table's primary or foreign key. A table can contain many foreign keys. The number is based on the number of tables that are related to it.
A One-to-one relationship means that you have a primary key field/column in Table_1 that is related to a foreign key field/column in Table_2, and that for every primary key value, there is one foreign key value.
One-to-one relationships occur when there is exactly one record in the first table that corresponds to exactly one record in the related table. This type of relationship can occur in a department that
has one manager and one employee. Another instance occurs when a social security number is a primary key in Table_1 and a foreign key in Table_2.
One-to-many relationships occur when each record in Table_1 may have many linked records in Table_2 but each record in Table_2 may have only one corresponding record in Table_1. This type of relationship exists when one person has multiple pets, but the pets have only one owner.
In business, this relationship occurs when a department manager is responsible for several employees.
In a hierarchical management organization, one employee will have several levels of management in his direct chain, and one manager may have several employees that are in his chain of responsibility. Another example is the military and the chain of command. A general may have several people reporting to him/her, and a Private may have several levels of command that he reports to before reaching the general. In Figure 5 above, employee N has a relation with every manager in his management chain, where Manager 1 is his direct manager, Manager 2 is his second line manager, and Manager 5 is his fifth line manager.
The SELECT statement is arguably the most used command used to retrieve data from a database. To retrieve all of the columns/fields from a table, use the following format.
SELECT * FROM Table_name
I will be using Java and Microsoft Access to develop this tutorial.
The purpose of this introduction was to present a brief overview of: