The Basics of SQL Language


SQL ExplainedThe Basics of The SQL Language

The basic concepts of SQL are relatively simple if you can understand what it does at its core. For all intents and purposes SQL is a language for accessing databases that store information in tables. By storing information in the form of spreadsheets, you can quickly and easily access the data by giving different search parameters depending on the action you wish to perform.

The Database
A good example of the type of database SQL can interact with is a spreadsheet that contains a company’s employee roster and is called “Employees”. This employee roster will have multiple columns for inputting information such as address, date of birth, and phone numbers to name a few. Each different column will be labeled according to the bit of information it stores, meaning to search for anything that has entered into the database is as simple as performing a search query. Using an SQL database program gives you many more ways to interact with your database tables including updating, deleting, creating new tables, and more.Basic SQL Commands
There are quite a few commands for SQL, and depending on the actual software you’re using there can be an endless list of them. Different types of SQL database software use different variations of the language itself, but there are always going to be a standard set of basic commands if the program is to be labeled as SQL. Here are some of the basics:

  • Select – extracts data
  • Update – updates data
  • Delete – deletes data
  • Create Database – creates a new database
  • Alter Database – modifies an existing database
  • Create Table – creates a new table
  • Alter Table – modifies an existing table
  • Drop Table – deletes a table
  • Insert Into – inserts data into an existing database

It’s important to know that the SQL language is not case sensitive. They are capitalized here to make it a bit easier on the eyes, so don’t feel impelled to have perfect grammar while working with SQL.

Breaking Down a Statement
A helpful way to look at statements for any programming language is to view them as a math equation, and SQL is no different. Every part of the statement serves a purpose, and for the software to reach a logical conclusion it’s up to you to enter the appropriate information into each field.

A very basic example is a simple math problem. If your end goal is the number 4, how do you get there? You can do 2+2 or 1+3, and in the end your result is the same. SQL is very similar in to get your desired result, you simply have to input the proper equation. Looking at examples of standard statements will help explain it in more detail.

Going back to the example of an employee roster from a hypothetical company, if we have basic information put into the table we can perform basic statements. Here are a few facts about our table:

  • Employees – name of the table.
  • EmployeeName – The first column, naming each individual employee.
  • City – The city each employee lives in.

Now that we have a table named Employees with a list of employees and their home city, we can perform a statement to find an answer to a question we might have. If your tables have an enormous amount of information available, the different statements that SQL can use will really shine.

Select statement – If you’re looking to retrieve information, the select statement is the simplest way to do that. Here is what the statement will look like:

Select column_name,column_name
From table_name;

Breaking it down, the first part is telling your program what you’re trying to do, in this case the “select” statement. After select, you’ll see that we have column_name two times with no spaces and a comma in between.

Finally, the “from” will tell SQL where to look for the information, and that location is table_name followed by a semicolon.

To access the information in your database on your table, the exact command will look like this:

Select EmployeeName,City
From Employees;

If you have the a table named Employees, the above command will immediately give you a table showing exactly what you had searched for, which in this case would be employee names and their home city. The table that you’ll see after entering a statement is called the “result set”.

The Uses of SQL
As mentioned previously, there are more commands available for SQL than can be listed in any easily readable format. As you tinker with SQL, you’ll realize that it’s an enormously powerful language that gives you complete control over your stored databases. To do more with SQL only requires you finding the exact statements that will do the action you’re looking for. A helpful table can be found here with a detailed breakdown of numerous basic statements.

In the case of WordPress, the useful aspects of an SQL program only increase. WordPress stores nearly all information in database tables. When you’re looking to perform any action on your WordPress website, there are an enormous amount of SQL statements available to help you do just about anything.

Deleting comments depending on age, clearing stored data from the automatically generated drafts that each comment and post includes, and numerous other actions are easily accessible by learning different SQL commands. After this tutorial outlining the basics, hopefully the general premise of how SQL operates and what it needs to do its job are clear.


Leave a Reply