Databases with SQLite

Tables

If you've read a few of the books available in the Resources page, you know that relational databases are made up of tables.

In the context of relational databases, tables are smaller collections of attributes related to what the table represents.

Previously, we discussed creating a database of books - a library of non-fiction, digital books.

Designing databases is not a trivial task, and is not done in the top - down manner.

Instead we start at the inside, and work our way out.

So to build our database from the inside, what obvious things will help us find and access a book in our library?

Three things come to mind: information about the book; information about the author/s; some subject headings.

Those 3 things will be the tables that make up our database. Now we need to know exactly what to put in them.

For example, in a books table, what do we need that is part of a 'book' definition?

Recall we discussed relations, and how we used a unique number to indentify something?

Do not avoid this crucial step, it is ESSENTIAL to a properly designed database

Now we're going to use them in our books table:

That is a reasonably good description of any book you might have in your library of non-fiction, digital books.

Your description may be slightly different - perhaps you don't need the ISBN or publisher, so leave them out.

Whatever you decide here will be the columns of our table. The rows will be the information about each column.

Likewise, we need an authors table:

You may think you should have a book title for the author in here, but that would be a mistake, as we will see later in normalization.

Not much else needed there.

Many books have multiple authors, which you will be adding to your database.

Depending on your needs, you could decide to have each author of a book as a separate entry in the authors table, or group them all together.

Finally we need a subject or keyword table:

With that design, we can now finally move on to creating a database.

DB Datatypes