Introduction to SQL
SQL (Structured Query Language) is the standard language used to communicate with relational databases like MySQL, Oracle, PostgreSQL, and Microsoft SQL Server, etc. Just as humans understand languages like English, all relational databases understand SQL.
First SQL query
Now let's look at how a sample SQL Query looks like in real world, don't worry if this looks too complicated at this point, you will learn it soon in the up coming chapters.
Below is a sample query to read data from a table called employees.
select * from employees;
Following is the explanation for each of the component in the query.
+--------+ +---+ +------+ +-----------+ +-+
| SELECT | -> | * | -> | FROM | -> | employees | -> |;|
+--------+ +---+ +------+ +-----------+ +-+
| | | | |
| | | | |
Retrieve All Data Table End of
data columns Source Name command
Now let's understand some of the basic terminology in SQL
Table:
Think of a table like a spreadsheet — it stores information in rows and columns. Each row is a record, and each column is a different type of information. For example, the Employees table stores employee names, departments, and IDs.
+---------------------------+
| Employees | <--------- Table Name
+----+--------+-------------+
| id | name | department | <--------- Columns
+----+--------+-------------+ <-
| 1 | Alice | HR | |
| 2 | Bob | IT | |
| 3 | Carol | IT | |------- Rows
| 4 | David | Sales | |
| 5 | Emma | Finance | |
+---+---------+-------------+ <-
Database:
A database is a collection of tables that are related and work together. For example, a company might use a database called Company DB that has tables like employees, departments, salaries, and more.
+---------------------------+
| Company DB |
+---------------------------+
| (employees) (salaries) |
| (departments) (leaves) |
| (projects) (...) |
+---------------------------+
RDBMS:
An RDBMS (Relational Database Management System) is software that lets you create and manage databases using SQL. It's like the engine that runs your database. Popular ones include MySQL, PostgreSQL, Oracle, and SQL Server.