# Basic SQL Statements

<table data-view="cards"><thead><tr><th align="center"></th><th align="center"></th><th align="center"></th><th data-hidden data-card-cover data-type="files"></th></tr></thead><tbody><tr><td align="center"><strong>WEBINAR</strong></td><td align="center">MariaDB 101: Learning the Basics of MariaDB</td><td align="center"><a href="https://go.mariadb.com/MariaDB101-2024-10-16_Registration-LP.html?utm_source=onpagepromo&#x26;utm_medium=kb&#x26;utm_campaign=webinar-mariadb-101"><strong>Watch Now</strong></a></td><td><a href="broken-reference">Broken file</a></td></tr></tbody></table>

This page lists the most important SQL statements and contains links to their documentation pages. If you need a basic tutorial on how to use the MariaDB database server and how to execute simple commands, see [A MariaDB Primer](mariadb-usage-guide-1).

Also see [Common MariaDB Queries](../../mariadb-quickstart-guides/mariadb-advanced-sql-guide) for examples of commonly-used queries.

## Defining How Your Data Is Stored

* [CREATE DATABASE](../../reference/sql-statements/data-definition/create/create-database) is used to create a new, empty database.
* [DROP DATABASE](../../reference/sql-statements/data-definition/drop/drop-database) is used to completely destroy an existing database.
* [USE](../../reference/sql-statements/administrative-sql-statements/use-database) is used to select a default database.
* [CREATE TABLE](../../reference/sql-statements/data-definition/create/create-table) is used to create a new table, which is where your data is actually stored.
* [ALTER TABLE](../../reference/sql-statements/data-definition/alter/alter-table) is used to modify an existing table's definition.
* [DROP TABLE](../../reference/sql-statements/data-definition/drop/drop-table) is used to completely destroy an existing table.
* [DESCRIBE](../../reference/sql-statements/administrative-sql-statements/describe) shows the structure of a table.

## Manipulating Your Data

* [SELECT](../../reference/sql-statements/data-manipulation/selecting-data/select) is used when you want to read (or select) your data.
* [INSERT](../../reference/sql-statements/data-manipulation/inserting-loading-data/insert) is used when you want to add (or insert) new data.
* [UPDATE](../../reference/sql-statements/data-manipulation/changing-deleting-data/update) is used when you want to change (or update) existing data.
* [DELETE](../../reference/sql-statements/data-manipulation/changing-deleting-data/delete) is used when you want to remove (or delete) existing data.
* [REPLACE](../../reference/sql-statements/data-manipulation/changing-deleting-data/replace) is used when you want to add or change (or replace) new or existing data.
* [TRUNCATE](../../reference/sql-statements/table-statements/truncate-table) is used when you want to empty (or delete) all data from the template.

## Transactions

* [START TRANSACTION](../../reference/sql-statements/transactions/start-transaction) is used to begin a transaction.
* [COMMIT](../../reference/sql-statements/transactions/commit) is used to apply changes and end transaction.
* [ROLLBACK](../../reference/sql-statements/transactions/rollback) is used to discard changes and end transaction.

### A Simple Example

```sql
CREATE DATABASE mydb;
USE mydb;
CREATE TABLE mytable ( id INT PRIMARY KEY, name VARCHAR(20) );
INSERT INTO mytable VALUES ( 1, 'Will' );
INSERT INTO mytable VALUES ( 2, 'Marry' );
INSERT INTO mytable VALUES ( 3, 'Dean' );
SELECT id, name FROM mytable WHERE id = 1;
UPDATE mytable SET name = 'Willy' WHERE id = 1;
SELECT id, name FROM mytable;
DELETE FROM mytable WHERE id = 1;
SELECT id, name FROM mytable;
DROP DATABASE mydb;
SELECT COUNT(1) FROM mytable; gives the NUMBER OF records IN the TABLE
```

_The first version of this article was copied, with permission, from_ [_Basic\_SQL\_Statements_](https://hashmysql.org/wiki/Basic_SQL_Statements) _on 2012-10-05._

<sub>_This page is licensed: CC BY-SA / Gnu FDL_</sub>

{% @marketo/form formId="4316" %}
