Loading lessons...
SQL Syntax
SQL Syntax
Almost everything you do in SQL is a statement. A statement is a command that tells the database what to do.
The most common statement
SELECT * FROM Customers;
SELECT- "give me data".*- "all columns".FROM Customers- "from the Customers table".;- every statement ends with a semicolon.
Some more examples
SELECT CustomerName, City FROM Customers;
SELECT CustomerName FROM Customers WHERE Country = 'Germany';
INSERT INTO Customers (CustomerName, City) VALUES ('Cardinal', 'Stavanger');
The three main parts
- SELECT - which columns you want.
- FROM - which table they come from.
- WHERE (optional) - which rows to filter by.
Notes on text and numbers
- Text values go in single quotes:
'Germany'. - Numbers have no quotes:
WHERE Price > 30.
Comments
Use -- for a single-line comment and / ... / for a multi-line comment:
-- Select all customers
SELECT * FROM Customers;
TL;DR
- SQL statements tell the database what to do and end with
;. SELECT columns FROM table WHERE conditionis the core pattern.- Text uses single quotes; numbers do not.
--starts a comment.