Structured Query Language
Structured Query Language (SQL)
General Understanding
- SQL is a standardised language for managing and manipulating databases.
- It is designed to handle data in a relational database management system (RDBMS) or for stream processing in a relational data stream management system (RDSMS).
- SQL is both declarative and procedural, allowing you to describe what you want done, and also how it should be done.
Basic Commands
- SELECT is the most common SQL command, used to query the database for specific data.
- INSERT INTO adds new data into a database.
- UPDATE modifies the records in a database.
- DELETE removes records from a database.
- CREATE DATABASE creates a new database.
- ALTER DATABASE modifies the structure of a database.
- CREATE TABLE creates a new table in the database.
- ALTER TABLE modifies the structure of a table.
Advanced Functions
- JOIN is used to combine rows from two or more tables, based on a related column between them.
- Inner JOIN returns records that have matching values in both tables.
- Left (Outer) JOIN returns all records from the left table, and the matched records from the right table.
- Right (Outer) JOIN returns all records from the right table, and the matched records from the left table.
- Full (Outer) JOIN returns all records when there is a match in either the left or the right table.
Implementing SQL in Programming
- SQL commands can be embedded in other programming languages using SQL libraries.
- These libraries provide the methods to connect to the database, execute SQL commands and process the results.
Security and Integrity
- GRANT gives user’s access privileges to a database.
- REVOKE withdraws user’s access privileges to a database previously granted.
- SQL also provide constraints which are used to specify rules for the data in a table. Constraints are used to limit the type of data that can go into a table.