Databases
- Database management systems (DBMS) contains tables with records, which are rows that have a value for each column.
- Every table has columns and rows
- A column has a name and a type
- A row has a value for each column
- The Structured Query Language (SQL) is perhaps the most widely used programming language used to manage databases.
- It is a domain-specific language.
- It is also a declarative programming language.
Declarative Programming
- In Declarative programming:
- A program is a description of the desired result
- The interpreter will fiture out how to generate the result.
- This contrasts to Imperative Programming where we have to specify the full instructions about how to get there.
- Because of this, Imerpative programming is a lot more versatile, whereas the declarative language is more domain specific.
Structured Query Language (SQL)
Naming Tables
- A select statement creates a new table and displays it.
- We “create” a new version of the table and that table is what we display.
- A create table statement names the result of a select statement. This actually creates a new table and assigns a name to it.
Select Statements Project Tables
- A select statement can specify an input table using a from clause
- A subset of the rows of the input table can be selected using a where clause
- An ordering over the remaining rows can be declared using an order by clause
- Syntax:
SELECT <column names> FROM <table name> WHERE <condition> ORDER BY <order>;
- Column names are seperated by commas
- Syntax:
SELECT <expression> AS <name>, <expression> aAS <name>,...
- We may also create a table with select statements
CREATE TABLE <track_names> AS SELECT <column names> FROM <table name> WHERE <condition> ORDER BY <order>;
DROP
- We may drop (remove) a table.
Commands
- built-in commands vs SQL statements