Learning SQL
Using 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.
When working with tables, the keywords SELECT, INSERT, UPDATE, and DELETE are used. For table themselves, CREATE TABLE, ALTER TABLE, and DROP TABLE.
There are also keywords for working directly with databases (collections of tables). These are SHOW DATABASES, CREATE DATABASE, BACKUP DATABASE, and DROP DATABASE.
SHOW DATABASES
To see a listing of all of the databases, the keywords SHOW DATABASES can be used.
SHOW DATABASES
Note: The keywords SHOW DATABASES is different than the use of the singular DATABASE keyword used combinations to add or remove databases.
CREATE DATABASE
Like with working with tables, the name of the database to create follows its keyword.
CREATE DATABASE Demo
BACKUP DATABASE
When working with databases, it is important to have a backup strategy in mind. The keywords BACKUP DATABASE can be used for this purpose.
BACKUP DATABASE Demo
TO DISK
The keywords TO DISK are used to signal where to save the database backup.
BACKUP DATABASE Demo
TO DISK = "backup.db"
WITH DIFFERENTIAL
Because some databases can potentially have one to hundreds of tables. These can create a very large backup file. To backup parts over time, based on the last update, the keywords WITH DIFFERENTIAL can be used.
BACKUP DATABASE Demo
TO DISK = "backup.db"
WITH DIFFERENTIAL
DROP DATABASE
For removing a database, the keywords DROP DATABASE can be used.
DROP DATABASE Demo