
For an instructor lead, in-depth look at learning SQL click below.
Welcome budding developers! In this blog, we’re going to dive into the world of SQL (Structured Query Language). Specifically designed for managing and manipulating structured data in relational database management systems (RDBMS) or for stream processing in a relational data stream management systems (RDSMS), SQL is a standard language for accessing and manipulating databases.
Basic knowledge: What is SQL?
SQL (pronounced like “sequel”), stands for “Structured Query Language”. SQL allows us to access and manipulate data in databases. SQL became a standard of the American National Standards Institute (ANSI) in 1986 and the International Organization for Standardization (ISO) in 1987. Fostered but not owned by IBM, SQL offers powerful flexibility and functionality in handling databases—whether they are small or enterprise-level databases. With SQL, you can carry out tasks like update data, retrieve data, insert new data, and manipulate the structure of your database.
Basic SQL Commands
Before we write our first code, let’s understand the SQL commands. SQL commands are instructions used to communicate with the database to perform tasks, functions, and queries with data. They are categorized into Data Definition Language (DDL), Data Manipulation Language (DML), and Data Control Language (DCL).
1 2 3 4 5 6 7 8 |
--DDL commands: CREATE, DROP, ALTER, TRUNCATE CREATE TABLE Customers ( ID INT UNSIGNED NOT NULL AUTO_INCREMENT, NAME VARCHAR(20) NOT NULL, AGE INT NOT NULL, PRIMARY KEY (ID)); |
This DDL command creates a new table named Customers. Each table consists of columns with a data type (varchar, int, etc.) and a length.
1 2 3 4 |
-- DML commands: SELECT, INSERT, UPDATE, DELETE INSERT INTO Customers (ID, NAME, AGE) VALUES (1, 'John', 21); |
This DML command inserts a new record into the Customers table. The DML also includes SELECT to retrieve data, UPDATE to modify existing data, and DELETE to remove records.
Retrieving Data with SELECT
We retrieve data in SQL using the SELECT statement. Here’s an example where we retrieve all columns from the Customers table:
1 2 3 |
SELECT * FROM Customers; |
We can also retrieve specific columns:
1 2 3 |
SELECT NAME, AGE FROM Customers; |
Or use WHERE clause to filter rows:
1 2 3 |
SELECT NAME, AGE FROM Customers WHERE AGE >= 21; |
Summary
SQL is a powerful language used in software development for storing, retrieving and manipulating data in databases. In this crash course, we have scratched the surface of what SQL is capable of doing. The ultimate key to mastering SQL, like any other language, is through constant practice and implementation of the concepts in real-world scenarios.
Learn, Practice and Master SQL
Are you ready to dive deeper? Look for more advanced topics like JOINs, EXISTS, subqueries, indexes, and stored procedures. The power of SQL is endless. Happy querying!