SQL (Structured Query Language) has a specific set of rules and guidelines for writing commands. While different database systems (like MySQL, SQL Server, PostgreSQL) might have minor variations, the core syntax is standardized.
All the operations you perform on a database are done using SQL statements. A statement is simply a command that the database engine can understand and execute.
For example, the following statement selects all records from a table named Customers:
SELECT * FROM Customers;
Keywords are Not Case-Sensitive: SQL keywords like SELECT, FROM, WHERE, etc., are not case-sensitive. This means SELECT is the same as select or SeLeCt.
select * from Customers; -- This is valid
However, it is a widely-followed convention to write all SQL keywords in UPPERCASE to improve the readability of the code.
Table and Column Names: The case-sensitivity of table and column names depends on the specific database system and its configuration. For consistency and to avoid errors, it's best practice to always refer to tables and columns using the exact case they were defined with.
Semicolon as a Statement Terminator: Many database systems require a semicolon (;) at the end of each SQL statement. It is the standard way to separate multiple SQL statements, allowing you to execute more than one statement in the same call to the server. While some systems might not require it for a single statement, it is a good habit to always use it.
SELECT * FROM Customers; SELECT * FROM Orders;
Here are some of the most important and widely used SQL commands, which we will cover in detail in the upcoming chapters:
SELECT - extracts data from a databaseUPDATE - updates data in a databaseDELETE - deletes data from a databaseINSERT INTO - inserts new data into a databaseCREATE DATABASE - creates a new databaseALTER DATABASE - modifies a databaseCREATE TABLE - creates a new tableALTER TABLE - modifies a tableDROP TABLE - deletes a tableCREATE INDEX - creates an index (search key)DROP INDEX - deletes an indexBy convention, how should SQL keywords be written?