Database Reference
In-Depth Information
Dropping a column
An alter definition of an
ALTER TABLE
command to delete a column has the
following pattern:
DROP
<column_name>
For example, the following
ALTER TABLE
command will delete the
username
column
we created earlier:
ALTER TABLE employees DROP username;
Full documentation of the
ALTER TABLE
command is found at
https://mariadb.
com/kb/en/alter-table
.
Dropping a table
When we no longer need a table, just as when we no longer need a database, we
drop it. Out of the table commands, this one is by far the easiest. The basic syntax of
the command is:
DROP TABLE
<table_name>
If we try to drop a table that doesn't exist we will receive an error. We can suppress
the error with
IF EXISTS
.
Here are a couple of examples:
DROP TABLE mytable;
DROP TABLE IF EXISTS mytable;
If the table exists, the preceding two commands are equivalent. If the table doesn't exist
the first command will exit with an error and the second command with do nothing.
Full documentation of the
DROP TABLE
command can be found at
https://mariadb.com/kb/en/drop-table
.
Selecting, inserting, updating, and
deleting data
Getting data into and out of our database tables and updating, and deleting data when
necessary is where we will spend most of our time when working with MariaDB.