Database Design   «Prev  Next»

Lesson 6 Structured Query Language
ObjectiveWhy is SQL the common language of relational databases?

Why is SQL the Common Language of Relational Databases?

The lingua franca which bridges human beings with the world of databases is SQL. This language, SQL or Structured Query Language has earned its esteemed position as the universal language for relational databases through decades of evolution and innovation. Dive with me into this narrative, as we explore why SQL reigns supreme in within the realm of information retrieval.
  1. The Historical Imprint: The birth of SQL is intertwined with the genesis of relational databases. Edgar F. Codd, an expert at IBM, penned the relational model in the 1970s. Almost in tandem, SQL emerged, designed to work seamlessly with this model. It was no accident that SQL was embraced; it was tailored for the job.
  2. Intuitive and Accessible: One of SQL's undeniable virtues is its intuitiveness. Imagine trying to communicate with a database as if conversing with a person. With SQL, you "ask" a database a question using SELECT, you "tell" it to remove data using DELETE. This English-like syntax is approachable for beginners, while still being robust enough for experts, striking a rare balance between simplicity and power.
  3. Standardization: The American National Standards Institute (ANSI) standardized SQL in 1986, with subsequent endorsements by the International Organization for Standardization (ISO). This move was more than just a stamp of approval; it set the stage for consistency. Multiple database systems might have their dialects and nuances, but the core of SQL remains universally consistent, making skills transferable and widespread adoption easier.
  4. Versatility in Action: SQL's prowess isn't confined to merely querying data. Its versatility extends to data definition, manipulation, and control. Whether it's sculpting the structure of databases through Data Definition Language (DDL) or managing transactions with Transaction Control Language (TCL), SQL wears many hats with élan.
  5. A Unified Interface: Regardless of the underlying architecture, be it Oracle, Microsoft SQL Server, PostgreSQL, or myriad others, SQL provides a unified interface. It offers a singular touchpoint, simplifying interactions and abstracting complexities.
  6. Adaptable Evolution: While SQL's roots are deep-set in tradition, it's not trapped in time. With the proliferation of big data, SQL adapted. Extensions like SQL/OLAP cater to online analytical processing, while others like SQL/MM address multimedia databases. This adaptability ensures that SQL remains contemporary and relevant.
  7. The Ecosystem Influence: Software ecosystems orbit around SQL. Tools, libraries, and frameworks have been designed with SQL at their heart, further cementing its ubiquity. From data visualization tools to complex enterprise solutions, SQL's influence is palpable.

SQL is not just a language; it's a legacy. Its universality in the world of relational databases isn't a mere coincidence but the outcome of a potent blend of history, design, adaptability, and widespread acceptance. So, the next time you draft an SQL query, remember, you're not just typing commands, you are engaging in a rich dialect that bridges human intent with digital realms, a language that has become the very heartbeat of relational databases.

SQL Adoption

(SQL, pronounced “sequel”) Structured Query Language has been adopted internationally as the standard language for creating relational databases. It is considered the common language of relational databases because it serves as both a (DDL) data definition language[1] and (DML)data manipulation language[2] .
Data Definition Language
As a data definition language (DDL), SQL contains statements that:
  1. Create (and delete) tables
  2. Modify tables (add, delete, or change fields)
  3. Create (and delete) user views

Let us take another look at the Employees table.
Employees table containing 1) primary key EmpID 2) fields a) LastName, b) FirstName, c)HireDate
SQL Table: Employees table containing 1) primary key EmpID 2) fields a) LastName, b) FirstName, c)HireDate
A table labeled "Employees" with columns for `EmpID`, `LastName`, `FirstName`, and `HireDate`.
Here's the SQL representation for creating a table based on the image you described:
CREATE TABLE Employees (
    EmpID INT,
    LastName VARCHAR(255),
    FirstName VARCHAR(255),
    HireDate DATE
);

INSERT INTO Employees (EmpID, LastName, FirstName, HireDate) VALUES
(77920, 'Jackson', 'Stephen', '1997-11-29'),
(77921, 'Reynolds', 'Sandy', '1993-01-04'),
(77922, 'Armstrong', 'Stephen', '1989-09-16'),
(77823, 'Jackson', 'Linda', '1996-10-09');

This SQL code first creates a table called `Employees` and then inserts the rows as depicted in the diagram.

The section of the Employees table outlined in red contains the actual structures (one table with four fields) created by SQL statements. To specify EmpID as the primary key field for the table requires an additional statement.


Create Database Table using SQL

SQL statements
CREATE TABLE Employees(
 EmpID numeric,
 LastName varchar(20),
 FirstName varchar(15),
 HireDate date,
 Primary key (EmpID));

The table consists of the following columns:
  1. EmpID
  2. LastName
  3. FirstName
  4. HireDate
  5. The EmpID column is the primary key

  1. Create table Employees, Creates the Employees table.
  2. EmpID numeric, Creates the EmpID field and specifies that the data values entered in the field must be numbers.
  3. LastName varchar (20), Creates the LastName field and specifies that the data values entered in the field may contain up to (but no more than) 20 characters.
  4. FirstName varchar (15), Creates the FirstName field and specifies that the data values entered in the field may contain up to (but no more than) 15 characters.
  5. HireDate date, Creates the HireDate field.
  6. Primary key (EmpID), Creates a primary key field and specifies that EmpID is the primary key of the table.

Using Command Line Client of MySQL

After you install MySQL, give the Command Line Client a try. The following steps walk you through some simple database actions.
  1. Start the Command Line Client: Assuming you used a typical installation in Windows, open the Start menu and select
    All Programs -> MySQL -> MySQL Server 5.0 -> MySQL Command Line Client. 
    

    When it prompts you for the database's password, enter the password you used when you installed MySQL.
  2. List the available databases: Enter the command SHOW DATABASES;. (Remember to end each command with a semicolon and press Enter.) The Client should list the available databases running in MySQL.
  3. Select the mysql database: Enter the command USE mysql;. This makes the Client use the database named mysql.
  4. List the database's tables: Enter the command SHOW TABLES;. This makes the Client list the tables in the mysql database.
  5. Select some data: Most of the mysql database's tables will be empty, but the user table should hold one record for the root user that was created when you installed MySQL. Enter the command
    SELECT user, password FROM user;
    
    The Client should list a single record showing the user name root and that user's password. You will not be able to read the password because it is encrypted.
  6. Create a new database: enter the command CREATE DATABASE testdb;. To select the new database, enter the command USE testdb;. If you execute the SHOW TABLES command now, you should find that the new database contains no tables.
  7. Create a table by using a SQL CREATE TABLE statement. This is a long, potentially complex statement that can span several lines. For this example, enter the command:

CREATE TABLE People (
FirstName VARCHAR(40) NOT NULL,
LastName VARCHAR(40) NOT NULL,
PRIMARY KEY (FirstName, LastName)
);

The following diagram below contains the 1) SQL create statement and resulting 2) column fields of the table.
Create Table using SQL
  1. Creates the Employees table
  2. Creates the EmpID field and specifies that data values entered in the field may contain up to 15 characters.
  3. Creates the LastName field and specifies that the data values entered in the field may contain up to 20 characters.
  4. Creates the FirstName field and specifies that the data values entered in the field may contain up to 15 characters.
  5. Creates the HireDate field.
  6. Creates a primary key field and specifies that “EmpID” is the primary key of the table.

Different Dialects of SQL

SQL comes in several dialects, so the syntax of statements is not uniform. For example, one dialect may require parentheses to enclose certain elements in SQL statements, another may use colons between elements, and so on.
  • Data Manipulation Language As a Data Manipulation Language (DML), SQL contains statements that manipulate data, enabling you to:
    1. Create queries
    2. Modify records (insert, delete, or update them)
    3. Invoke user views

    In addition, the DML capabilities built into SQL usually include mathematical and statistical calculations that assist in generating reports. In the next lesson, the functions of a relational database management system (RDBMS), whose major component is SQL, will be discussed.

[1](DDL) data definition language: A collection of programming statements that describe and define data and data relationships in a database. The data definition language is made of the commands used to change metadata in a database, such as creating tables, changing tables, and dropping tables.
[2](DML) data manipulation language: A collection of programming statements used to manipulate a database.

SEMrush Software