Difference between revisions of "SQL statement examples"
Karl Jones (Talk | contribs) (etc) |
Karl Jones (Talk | contribs) (Delete example) |
||
Line 77: | Line 77: | ||
Example: | Example: | ||
− | <code> | + | <code>DELETE FROM j_error_prod WHERE Fk_Error = 99 AND Fk_Prod = 999</code> |
=== Different implementations of SQL === | === Different implementations of SQL === |
Revision as of 09:35, 23 July 2015
This article demonstrates a variety of SQL statements.
Contents
Overview
SQL statements, broadly speaking, fall into four commonly used categories:
- SELECT statements return zero or more records
- INSERT INTO statements insert a new record
- UPDATE statements update existing records
- DELETE statements delete existing records
Case insensitivity
SQL statements are typically case-insensitive. These examples follow the common convention of uppercasing SQL keywords.
SELECT statements
SELECT statement return zero or more records.
Syntax:
SELECT column_name,column_name
FROM table_name;
Example:
...
INSERT INTO statements
INSERT INTO statements insert a new record into a database table.
The INSERT INTO statement has two forms:
- Specify values, do not specify columns
- Specify values and columns
Syntax (first form):
INSERT INTO table_name
VALUES (value1,value2,value3,...);/code>
Syntax (second form):
<code>INSERT INTO table_name (column1,column2,column3,...) VALUES (value1,value2,value3,...);
Example:
...
UPDATE statements
UPDATE statements update zero or more existing records in a database table.
Syntax:
UPDATE table_name
SET column1=value1,column2=value2,...
WHERE some_column=some_value;
Example:
...
DELETE statements
DELETE statements delete zero or more existing records from a database table.
Syntax:
DELETE FROM table_name
WHERE some_column=some_value;
If the WHERE clause is omitted, the DELETE query will delete all records in the specified table.
Example:
DELETE FROM j_error_prod WHERE Fk_Error = 99 AND Fk_Prod = 999
Different implementations of SQL
Note that different implementations of SQL -- different "flavors" -- may differ in their details. The examples on this page are appropriate to a wide range -- but not necessarily all -- implementations.
External links
- SQL SELECT @ W3Schools
- SQL INSERT INTO @ W3Schools
- SQL UPDATE @ W3Schools
- SQL DELETE @ W3Schools