What is SQL?

Louis Shi
Louis Shi
Aug 31, 2018 · 3 min read

SQL (Structured Query Language) is used to manage data in a database.

SQL differentiates from other programming languages because it serves to only talk to databases. As a result, it is often referred to as “special purpose” or “domain specific” programming language. Despite only having one purpose, it is used by many different database systems such as MySQL, PostgreSQL and SQLite.

Why is SQL so important?

As a Full-Stack Web Developer, we will frequently be working with databases to manage the data associated with applications.

For example, Facebook saves user data and stories — or persists — your associations with your friends and Amazon also has a very large database of items for sale.

Now we can do a quick check on installation of SQL on your computer, if you are using a mac, and are on OSX version 10.4 or greater, you most likely already have SQLite installed.

To check simply type this in your terminal:

and if the response back is:

then you already have sqlite3 already installed. (Appreciate it Macs).

If you do not have sqlite3 already installed, simply install with Homebrew by putting this in your terminal:

After installing Homebrew, you can install sqlite with:

For more information and questions about Homebrew, you can check out

https://brew.sh/.

Next, let’s go over some simple SQL database basics in creating tables.

To create a new database, just open up your terminal and type sqlite3 (database name).db. For example, sqlite3 animal_database.db. After that you can enter the command CREATE TABLE (table_name) such as CREATE TABLE chimps;

You may get an error message such as:

The reason for this error is because it expects us to include at least some definition of the structure of this table as well. Please see the example below:

In the example above, we have 3 columns, id, name and age; id’s data type is an integer, name’s data type is a text and age’s data type is an integer. The id is the primary key which is why it has primary key after it.

Next to add a column to a table, simply type ALTER TABLE (table_name) ADD_COLUMN (column_name) (data_type).

To check the schema of the update table simply type .schema and it will return the columns and the column’s data types of each.

Also, be sure if you ever want to delete a table simply type DROP TABLE (table_name).

If you ever want to exit the sqlite command, simply type ‘.quit’.

For a quick reference, here is the link to the list of SQL keywords; https://www.w3schools.com/sql/sql_quickref.asp. Here is also a wikipedia link to more history and information fo SQL; https://en.wikipedia.org/wiki/SQL. For some links to tutorials, please checkout https://www.youtube.com/watch?v=_vFiyFaQCPA, and https://www.youtube.com/watch?v=9Pzj7Aj25lw.

I hope you enjoyed this quick tutorial of SQL and have an excellent day!

Software Developer

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade