From the course: MySQL Essential Training (2019)

A brief overview of SQL

- [Instructor] Structured query language or SQL is the common language for querying and manipulating data in a relational database management system. Every system has its own variation of SQL and MySQL is no different. The basics are the same but the details can be very different. An SQL statement begins with a keyword and ends with a semi colon. Technically the semi colon is a statement terminator in SQL, that means that it's always required. Some systems, including MySQL, use the semi colon more as separator in some context. This means that it's not always required if there's only one statement. The semi colon is always allowed so it never hurts to use it and I strongly recommend that you get in the habit of using it all the time. SQL statements are not case sensitive. This means that capital letters and lowercase letters are treated as the same so these two statements are effectively the same. By default most symbols in MySQL are also not case sensitive, but there are exceptions. In this example the table name may or may not be case sensitive so these two statements may or may not be equivalent. If your MySQL server is running on Windows or a Mac, the table name will not be case sensitive and these two statements will be equivalent. But if your MySQL server is running on a Unix system or any operating system with a case sensitive file names the table name may be case sensitive and these two statements may refer to two different tables. Keep in mind that MySQL allows configuration options that may change this behavior. It is possible to configure your server so that all symbols are case sensitive. So I suggest that you always write your SQL consistently, including the case or your symbols, this will make your code as portable as possible. Remember that your server is often running on a different operating system than your desktop, so even if your desktop in on a Windows or a Mac system, your server may not be. This is an example of a standard line oriented SQL comment. The comment is introduced by a double dash followed by at least one space and it ends at the end of the line. Specifically the comment is introduced by two hyphen characters with no space between them and at least one space character after the second hyphen. This is followed by the comment text and the comment text is terminated with a new line. MySQL also recognizes c-style comments, this conforms with the latest SQL standard. This allows multi line comments with much more ease than line oriented comments. MySQL also recognizes single line comments introduced with the pound character. This is not standard SQL, I recommend that you avoid using this style of comment. You may see this in very old MySQL code and I recommend that you change those comments to use the double dash form. A statement may have one or more clauses depending on the syntax of the statement. For example this SELECT statement has a FROM clause and a WHERE clause. The FROM clause specifies the table and the WHERE clause specifies a condition that must be satisfied for each of the rows selected. Functions are used to perform specific operations on data. In this example the COUNT function is used to find the number of rows matching the condition in the WHERE clause. Expressions are used in SQL to derive values from data, for example this statement has two expressions. This expression divides the population column by one million in order to display the population in millions. And this logical expression is used to select only those rows where the population column is greater than or equal to one million. The structure of SQL syntax is very simple but the rules can be complex, depending on the statements and the usages. In the rest of this course we'll look at specific details of many usages. For a complete tutorial on SQL please see my course SQL Essential Training.

Contents