Learning SQL
Structured Query Language (SQL) is a declarative programming language used for accessing data storied in relational databases. It appears in or is a core part of many common software packages like MySQL, PostgreSQL, Microsoft SQL Server, and Oracle Database.
In SQL, there are four common operations: SELECT, INSERT, UPDATE, and DELETE. Each of these corresponds in order to a primary action in relation to data: getting, adding, changing, and removing.
DELETE
To remove data from a table, the keyword DELETE is used.
Table Name: People | |
ID | Name |
1 | Dan |
2 | Chad |
FROM
Like with the SELECT keyword, the DELETE keyword needs to know from which table to remove the data.
DELETE FROM 'People'
WHERE
Similar to how the UPDATE keyword needed a conditional to make sure the whole table was not changed, so too does DELETE. It also uses theWHERE keyword.
DELETE FROM 'People' WHERE 'ID' = '1'
Table Name: People | |
ID | Name |
2 | Chad |
Deleting All Data
Without the WHERE keyword, the DELETE keyword would remove all data from a table.
DELETE 'People'
Table Name: People | |
ID | Name |
Quotations and Keywords
Depending on the software used with SQL, it may not use quotations around column and table names. Some allow for column and table names to appear as lowercase alongside the uppercase keywords. Nearly always, though, the keywords themselves appear as all-uppercase letters regardless of how the column and table names themselves appear.