
For an instructor lead, in-depth look at learning SQL click below.
Welcome to SQL 101, a beginner’s guide to understanding and writing SQL – Structured Query Language – codes. SQL is a standard language for storing, manipulating, and retrieving data in databases. If you want to dive into the world of data analytics or manage databases, understanding SQL is non-negotiable. In this guide, we will focus on the fundamentals.
Understanding SQL
SQL stands for Structured Query Language. It’s used to communicate with and manipulate databases. It is particularly useful in handling structured data, i.e., data incorporating relations among entities and variables.
SQL Syntax
Learning SQL begins with understanding its syntax. The basic syntax for SQL involves a command followed by the name of the table you want to operate on.
|
1 2 3 4 5 |
-- An example of the basic SQL syntax would be: SELECT column1, column2 FROM table_name; |
The SQL commands are NOT case sensitive: select is the same as SELECT.
SQL Commands
There are several SQL commands, but for this guide, we will focus on the most common ones: SELECT, WHERE, INSERT INTO, UPDATE, DELETE, and ORDER BY.
SELECT
In SQL, the SELECT statement is used to select data from a database. The data returned is stored in a result table, called the result-set.
|
1 2 3 4 |
-- Here is an example of using SELECT: SELECT * FROM Employees; |
This code will select all data from the table named “Employees”.
WHERE
The WHERE keyword is used to filter records, and is used to extract only those records that fulfill a specified criterion.
|
1 2 3 4 |
-- An example of using WHERE SELECT * FROM Employees WHERE Age > 30; |
This code will select all data from the “Employees” table where the “Age” is greater than 30.
INSERT INTO
The INSERT INTO statement is used to insert new records in a table.
|
1 2 3 4 5 |
-- An example of using INSERT INTO INSERT INTO Employees (FirstName, LastName, Age) VALUES ('John', 'Doe', 30); |
This code will insert a new record to the “Employees” table with ‘John’ as FirstName, ‘Doe’ as LastName, and 30 as Age.
UPDATE
The UPDATE statement is used to modify the existing records in a table.
|
1 2 3 4 5 6 |
-- An example of using UPDATE UPDATE Employees SET Age = 31 WHERE FirstName = 'John' AND LastName='Doe'; |
This code will update the ‘Age’ to 31 for the record in the ‘Employees’ table where ‘FirstName’ is ‘John’ and ‘LastName’ is ‘Doe’.
DELETE
The DELETE statement is used to delete existing records in a table.
|
1 2 3 4 |
-- An example of using DELETE DELETE FROM Employees WHERE FirstName = 'John' AND LastName='Doe'; |
This code will delete the record in the ‘Employees’ table where ‘FirstName’ is ‘John’ and ‘LastName’ is ‘Doe’.
We hope this guide provides a good starting point for your SQL journey. Remember, practice is key in mastering SQL. happy querying!
