code
16px-Pencil

SQL (Structured Query Language) is a language used for querying databases. It is an imperative language composed by instructions which include clauses and expressions.

There are some SQL sub-languages:

Most database managers implement their own dialect of the language with their own proprietary language extensions. Some standards exist, though:

Examples

Selecting all rows that meet a certain condition.

SELECT <column names> FROM <tablename>
WHERE <condition>;

Inserting a new row into a table

INSERT INTO <tablename> (<column names>) VALUES (<values>);

Deleting all rows in a table that meet a certain condition.

DELETE FROM <tablename> WHERE <condition>;

Updating a content of a row meeting a certain condition.

UPDATE <tablename> SET <values> WHERE <condition>

SQL injection

SQL injection is the most basic security issue caused by sanitized input from users. The only way to defend against them is to use parameterized inputs:

txtUserId = getRequestString("UserId");
txtSQL = "SELECT * FROM Users WHERE UserId = @0";
db.Execute(txtSQL,txtUserId);

Parameters ensure that values are treated literally, and will not be used to execute code.

The exact method used to parameterize SQL is based on the programming language, but is easily learned from the documentation.