No history yet

Introduction to SQL

What is SQL?

Structured Query Language, or SQL, is the language you use to talk to databases. Think of a database as a massive, perfectly organized digital filing cabinet. You need a special language to ask that cabinet to find, add, or change information for you. That language is SQL.

SQL is your tool for asking a database questions and giving it commands.

Imagine you’re at a restaurant. You don't go into the kitchen and tell the chef how to chop vegetables and heat the pan. Instead, you look at a menu and tell the waiter what you want: "I'll have the steak, medium rare." The waiter understands your request and brings you the result. SQL works the same way. You write a "query"—a specific kind of request—to tell the database what information you want, and it delivers.

Organized in Tables

SQL works with a specific kind of database called a relational database. The "relational" part just means the data is organized into tables, like spreadsheets. Each table stores information about a specific thing, like customers, products, or orders. The tables are made up of rows and columns.

A column is a category of information (like "Name" or "Price"), and a row is a single record (like one specific customer or product).

For example, a Customers table might look like this:

CustomerIDFirstNameLastNameEmail
1MariaGarciam.garcia@email.com
2ChenWeichen.wei@email.com
3SamJonessamjones@email.com

And a Products table might look like this:

ProductIDProductNamePrice
101T-Shirt$20
102Mug$12
103Hat$18

The power of relational databases comes from linking these tables together. For instance, we could create an Orders table that uses CustomerID and ProductID to show who bought what. This structured approach keeps data organized and efficient.

What You Want, Not How to Get It

SQL is a declarative language. This is a key concept. It means you tell the database what you want, not how to get it. You declare your desired outcome, and the database management system (the software running the database) figures out the most efficient steps to make it happen.

This is different from a procedural language, where you have to write out every single step. Think about it like this: asking a friend for a cup of coffee is declarative. Writing a detailed list of instructions—boil water, grind beans, operate the coffee machine—is procedural. SQL saves you the trouble of managing the low-level details.

With SQL, you focus on the result, and the database handles the process.

Different Flavors

While SQL is a standard, different companies have created their own database management systems. These systems all speak SQL, but they might have slightly different dialects. This is similar to how English is spoken differently in the United States, England, and Australia. The core language is the same, but there are minor variations in vocabulary and grammar.

Some of the most popular SQL-based systems include:

MySQL: A very popular open-source system, widely used for web applications. PostgreSQL: Another powerful open-source system, known for its advanced features. Oracle Database: A commercial system often used by large corporations. Microsoft SQL Server: Microsoft's database system, popular in enterprise environments.

The good news is that if you learn the standard SQL commands, you can easily adapt to any of these systems. The fundamentals are universal.

Lesson image

A brief history lesson: SQL was developed at IBM in the 1970s, based on the ideas of the relational model. It was later standardized, which is why it's so widely used today. It has proven to be an incredibly durable and useful tool for managing data for decades.

Now that you understand the basic concepts, let's check your knowledge.

Quiz Questions 1/4

What is the primary purpose of SQL?

Quiz Questions 2/4

The idea that you tell the database what you want, not how to get it, makes SQL a _________ language.

You've got the foundational ideas down. Next, you'll start learning the actual commands to put this knowledge into practice.