Database Reference
In-Depth Information
ence I'd like you to notice: instead of using the column type of TEXT , we're using the
column type of CHAR , which stands for “character.” We can add text to this column, but
its size is limited: each row can have only a maximum of eight characters in this column.
That makes a smaller field and therefore a smaller and faster table. It doesn't matter in our
examples here, as we're not entering much data, but little specifications like this will
make a huge performance difference in large databases. It's good for you to start thinking
this way from the beginning.
The second SQL statement added two sets of values. Doing multiple sets of values inone
INSERT is allowed, and is easier than entering a separate line for each. Here's how the
data looks in that table:
SELECT * FROM status_names;
+-----------+-------------+
| status_id | status_name |
+-----------+-------------+
| 0 | Inactive |
| 1 | Active |
+-----------+-------------+
That's probably a seemingly useless table of data. But let's combine this table with the
first table, books , to see a glimpse of the potential of database system like MariaDB.
We'll usethe SELECT statement to join both tables together to get nicer results, and we'll
be selective about which data is displayed. Try this on your computer:
SELECT book_id, title, status_name
FROM books JOIN status_names
WHERE status = status_id;
+---------+------------------------+-------------+
| book_id | title | status_name |
+---------+------------------------+-------------+
| 100 | Heart of Darkness | Inactive |
| 101 | The Catcher in the Rye | Active |
| 102 | My Antonia | Active |
+---------+------------------------+-------------+
First, notice that I broke this SQL statement over three lines. That's allowed. Nothing is
processed until you type a semicolon and then press the Enter key. Breaking apart a state-
ment like this makes it easier to read, but has no effect on MySQL. In this SQL statement,
the first line selects book_id and title , which are both in books , and
status_name , which is in the status_names table. Notice that we didn't use an as-
Search WWH ::




Custom Search