
For an instructor lead, in-depth look at learning SQL click below.
Structured Query Language or SQL is a standard database language that is used to create, maintain, and retrieve data from databases like MySQL, Oracle, SQL Server, and PostgreSQL. This beginner’s guide will provide a great start to understanding the basics of SQL.
What is SQL?
SQL is a standard language for managing and manipulating databases. Whether you are accessing a bank’s database to see your transaction history or Instagram’s database to check out your friend’s new post, you’re likely to be using SQL.
The Basic Syntax
SQL is not case-sensitive. However, by convention, SQL keywords are often written in uppercase. We usually write SQL commands like SELECT, FROM, WHERE in uppercase and the table and column names in lowercase.
Let’s look at a simple example of an SQL query. In the following code, we’re asking the database to look up and return all content (* indicates ‘all’)from a theoretical ’employees’ table. This is an example of ‘Reading’ data.
1 2 3 |
SELECT * FROM employees; |
Creating Tables
Creating tables in SQL is just as straightforward. Here is a sample SQL command to create a table named ’employees’ with various fields such as id, first_name, last_name, and email.
1 2 3 4 5 6 7 8 |
CREATE TABLE employees ( id INT PRIMARY KEY, first_name VARCHAR(40), last_name VARCHAR(40), email VARCHAR(60) ); |
Inserting Data into Tables
Once the table is created, you can insert data into it. Below is an example of how to add a new row of data into the ’employees’ table.
1 2 3 4 5 |
INSERT INTO employees (id, first_name, last_name, email) VALUES (1, 'John', 'Doe', <a href="mailto:'john.doe@example.com'" >'john.doe@example.com'</a>); |
There is surely much more to SQL than these basics. However, understanding this initial groundwork provides the necessary foundation to expand your knowledge and start getting your hands dirty with large datasets.
Remember, you can’t become an expert overnight. Practice is key when it comes to mastering SQL or any programming language. Happy SQL learning!