
For an instructor lead, in-depth look at learning SQL click below.
As the world rapidly turns digital, enriching your skillset with SQL, a standard language for managing data held in relational database management systems, is invaluable. Let me simplify the process for you and show you how you can master SQL without a sideline in Hacker Script.
What is SQL?
SQL stands for Structured Query Language. It is designed for managing data in relational database management systems (RDBMS). SQL includes data insertion, query, update and delete, schema creation and modification, and data access control.
Basic SQL Commands
Before we delve into writing SQL code, I want to introduce you to the basic commands. Here are a few of them:
- SELECT: retrieves data from a database.
- UPDATE: modifies the records in a database.
- DELETE: removes records from a database.
- INSERT INTO: adds new records into a database.
- CREATE DATABASE: creates a new database.
- ALTER DATABASE: modifies a database.
- CREATE TABLE: creates a new table in the database.
- ALTER TABLE: modifies a table.
- DROP TABLE: deletes a table.
- CREATE INDEX: creates an index (search key).
- DROP INDEX: deletes an index.
Let’s Dive Into SQL Code
Now that you are familiar with the basic commands let’s observe them in action.
1 2 3 4 5 |
<!--Creating a database --> CREATE DATABASE TestDB; |
In this example, we’ve created a new database named TestDB. Let’s create a new table in TestDB.
1 2 3 4 5 6 7 8 9 10 11 |
<!--Creating a table --> CREATE TABLE TestDB.Employees ( ID int, Name varchar(255), Age int, Address varchar(255), Salary decimal(18, 2), ); |
This command creates a new table named Employees with five columns – ID, Name, Age, Address, and Salary. Now, let’s add some items to the table.
1 2 3 4 5 6 |
<!--Inserting values into the table --> INSERT INTO TestDB.Employees (ID, Name, Age, Address, Salary) VALUES (1, 'John', 28, '123 Fourth Ave', 1000.50); |
Great! We have added an employee named John to our table. Now, let’s retrieve our data.
1 2 3 4 5 |
<!--Retrieving data from the table --> SELECT * FROM TestDB.Employees; |
This command selects all data from the Employees table. You will see an output table displaying the data we just inserted.
That’s it! You just wrote your first SQL queries. With practice and experience, writing SQL will get much easier and faster.
Remember, data is the core of any business, and being able to effectively retrieve, manipulate and analyze it using SQL is a skill that is becoming increasingly important in today’s digitally driven world.