From the course: Learning SQL Programming

What is SQL? - SQL Tutorial

From the course: Learning SQL Programming

Start my 1-month free trial

What is SQL?

- [Instructor] SQL stands for Structured Query Language, which is a language for manipulating and defining data in databases. It first came into use in 1974 and became a standard in 1986. SQL gives us 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 cover 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. SQL gives us a way of writing questions a database can understand. Databases aren't clever and 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, a person, could pretty easily understand what I'm asking you. Even given just a list of team members, points, and shirt preferences, you could eventually figure it out. 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 the database software 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, Postgres, 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 Language, but was originally called SEQUEL, for Structured English Query Language. Maybe because of this, or because the letters themselves look a little bit 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 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 white space independent, meaning that if you want to add some space or lines 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 on statements later in the course. Clauses are the basic components of statements, the smaller building blocks that make up the whole thing. These clauses are constructed out of various elements including keywords, which are special or reserved words which tell the database to take some action, field names, which let us refer to fields or columns of data whose values we want to use, table names, which tell the database which table to use, and predicates, which we use to specify what information or condition we're looking for. 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 uppercase, 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 uppercase, even though we have some syntax highlighting that will also help differentiate them. At the end of a statement, we put a semi-colon. 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 to the end of a statement. So we need to be able to tell the database that we're done and that it can start figuring out what we're asking for. While the semi-colon is often required in order for database software to accept the statement as valid, not all database software enforces this. So it's a good idea to just get into the habit of using a semi-colon to end a statement as you would use a period to end a sentence. 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. A query suggests that we're asking a question and when we're using the select keyword, that's generally the case. SQL statements can also be used to add, modify, or delete data in a database or even to create, modify, and remove tables. When we use SQL to work with data in existing tables, that's SQL being used as a DML, or data manipulation language. These operations where we change data are generally called CRUD, short for create, read, update, and delete. CRUD is a common shorthand for referring to modifying data in a database. And the CRUD operations are central to working with databases. Crud is also something fun to say if you make a typo or mistake when working with SQL. When we write SQL to make changes to the structure of tables themselves or to change the database, that's SQL being used as a DDL, or data definition language. In this course, we'll focus on SQL as a data manipulation language working within existing tables. Once you're comfortable with that, you'll be ready to move onto courses which focus on the structure of databases.

Contents