Topics
Structured Query Language

Structured Query Language

Structured Query Language (SQL, pronounced as "sequel") is a language used for managing data stored in a relational database management system (RDBMS).

SQL includes commands (also referred to as SQL statements) for data query (find and read), data manipulation (create, update and delete), data definition (schema creation and modification), and data access control. SQL commands can be run from the database client or an application written in any high-level language. Every database has programs known as drivers that help the applications connect with the database. SQL can also be used to write programs that run directly on the database, these are known as Stored Procedures.

The most basic SQL statement is

SELECT * FROM Sensors

This retrieves all records from the Sensors table.

Some more simple statements are shown below, but in real applications, they can get much more complicated. The four primary operations on a database are referred to as CRUD (create, read, update, delete)

  • Create: INSERT statement The INSERT statement inserts a new record into a table with values for each field. The application can provide a value for the primary key, if it is sure about the uniqueness of the value, or it can ask the databases to generate a unique value for the primary key. In the latter case, the primary key will only be used to identify the record and will have no relevance to the application data.
INSERT INTO <table_name> (<field_name1>, <field_name2>)VALUES (<value 1>, <value 2>)
    • Read: SELECT statement The SELECT statement fetches data from a table. The command can fetch only the specified fields, or a * indicates that it should fetch all the fields. A WHERE clause can be included to find only records that match the specified condition.
SELECT * FROM <table_name>WHERE <filter_field> = <filter_value>
    • Update: UPDATE statement The UPDATE statement updates the values of one or more fields in a table with new values for the record or records that match the condition specified in the WHERE clause.
UPDATE <table_name>SET <field_name1> = <value 1>, <field_name2> = <value 2> WHERE <selector_field> = <selector_value>
    • Delete: DELETE statement The DELETE statement deletes one or more records that match the condition specified in the WHERE clause.
DELETE FROM <table_name>WHERE <selector_field> = <selector_value>