Find out what SQL stands for, what it's used for, and what it looks like.
- [Narrator] SQL stands for Structured Query Language, a language for manipulating and talking about data in databases. It first came into use in 1974 and became a standard in 1986. SQL is a standardized way of asking a specific question of a database or for making a structured query that a database knows how to respond to. There's a whole lot of formal math behind how SQL was designed and defined, but in this course we're not going to go over that. We'll focus on the practical usage of the language.
And, if you want to explore the academic history of SQL, I encourage you to do so. As I mentioned, SQL is about writing questions a computer can understand. Most databases aren't clever. They can't figure out meaning from a question the way a human can. If I were to ask you a question like how many people on the winning team asked for shirts, you can pretty easily understand what I'm asking you. Even given just a list of team members, points, and shirt preferences, you could figure it out eventually. But, give that same list to a database and ask the same question, and you'll probably get whatever the computer equivalent of a blank stare is.
The computer doesn't know how to understand the meaning or intention of my question. To make questions like this approachable for a database, we need to break them down into a series of smaller questions that are structured in a way that a database engine can understand. Because it's such a powerful way of thinking about data, SQL has been adopted into many database products. Some products support the SQL standard and add other features on top of it, and some support part, though not all, of the SQL standard. In this course, I'll cover the basic and widely supported parts of SQL that you're likely to use whether you're working with Microsoft Transact-SQL, or T-SQL, MySQL, PostgreSQL, SQLite, and others.
The way we say the name of this language can sometimes be a little bit confusing. The language is called SQL, or Structured Query Langauge, but was originally called SEQUEL, for Structured English Query Language. Maybe because of this, or because the letters themselves look like the english word sequel, some people pronounce the name of the language this way instead. This confusion extends to products with the name of the language in their names, like MySQL or Microsoft SQL Server. I tend to prefer switching back and forth a little bit, calling the language itself by the letters and saying sequel when it's easier to pronounce that way or when it flows better as part of the name of a product.
Both ways are acceptable, though some people have strong opinions about it. Just don't call it squeal or squirrel or anything like that. Before we start building SQL statements, we need to understand what the basic parts of a statement are. Overall, something you write in SQL to get an answer from a database or to make a change to it is called a statement. SQL is generally whitespace independent, meaning that if you want to add some space between clauses or expressions to make your statement easier to read, you can do so.
In this course, I'll break statements across various lines in order to make them more clearly readable. You can do this, too. I find it really helpful when I'm putting together a more complicated statement, so I can see what's going on. A statement is made up of clauses. Don't worry about what this actual statement does right now. We'll see how to make clauses and statements later in the course. Clauses are the basic components of statements, the smaller building blocks that make up the whole. And, these clauses are constructed out of keywords, which tell the database to take some action.
There are also field names, which tell the database where to look and what to look for. There's also predicates, which let us specify what information we're working with. Predicates include a value or condition called an expression. A clause can be a statement if you're writing a really basic one. There are also operators, as we'll see later on, which let us compare equality or ranges of data or treat information in other ways. These keywords and operators are customarily written as upper case, though usually, they don't have to be.
But, it helps to distinguish the SQL from your expressions and field names at a glance. In this course, I'll follow the custom of writing them in upper case, even though we have some syntax highlighting that will also help differentiate them. At the end of a statement, we put a semicolon. This tells the database that a statement has ended. That's important, because we can reconfigure some of the clauses in different ways and add more onto the end of a statement. So, we need to be able to tell the database that we're done, that it can start figuring out what we're asking for. Any SQL we write that takes some kind of action is a statement, and sometimes you'll see a statement using the SELECT keyword called a query instead.
- What is SQL?
- Asking for data with SELECT
- Limiting database responses
- Organizing responses
- Asking for data from two or more tables
- Understanding join types and data types
- Transforming data
- Performing math
- Adding and modifying data in a table