
For an instructor lead, in-depth look at learning SQL click below.
This guide provides a comprehensive look at the fundamentals of SQL, a powerful language used for handling structured data. Whether you are a beginner just starting in computer programming or a seasoned programmer with several languages under your belt, SQL is a great tool to add to your framework.
What is SQL?
SQL, or Structured Query Language, is a database programming language designed for managing data stored in a Relational Database Management System (RDBMS), or for processing data streams in Real-time Application Systems (RTAP). It was developed by IBM in the 70s and is a standard language for interacting with databases.
Getting Started with SQL
SQL Syntax
Let’s begin by exploring some basic SQL commands.
1 2 3 4 |
-- This is a simple command to select all data from a table SELECT * FROM table; |
The SELECT
command is used to select data from a database. The data returned is stored in a result table, called the result-set. *
is a wildcard character that means “everything”. In this case, we’re selecting all columns from the table
.
1 2 3 4 |
-- This command selects only the "column1" and "column2" data from the table SELECT column1, column2 FROM table; |
Filters in SQL
We can filter the results returned from our queries using the WHERE clause.
1 2 3 4 |
-- This command selects all data from the table where column1 equals 1 SELECT * FROM table WHERE column1 = 1; |
Manipulating Data
SQL is not only used for retrieving data, but also for updating, inserting, and deleting it.
1 2 3 4 |
-- This command updates the table and sets column1 to 3 where column2 equals 2 UPDATE table SET column1 = 3 WHERE column2 = 2; |
1 2 3 4 |
-- This command inserts new data into the table INSERT INTO table (column1, column2) VALUES ("value1", "value2"); |
1 2 3 4 |
-- And this command deletes data from the table where column1 equals 4 DELETE FROM table WHERE column1 = 4; |
Conclusion
This guide covered the basics of SQL, but there’s still much more to learn. Experiment with creating your own tables and trying out different queries. Database management is a useful skill for any programmer, and SQL is the building block for mastering it. Happy coding!
1 |