the best type to use for the others is INT. You should notice something else
about the cd_collection table: One of the CDs is missing a rating,
perhaps because we have not listened to it yet. This value, therefore, is
optional; it starts empty and can be filled in later.
You are now ready to create a table. As mentioned earlier, you do this by
using the CREATE statement, which uses the following syntax:
Click here to view code image
CREATE TABLE table_name (column_name column_type(parameters) options,
...);
You should know the following about the CREATE statement:
SQL commands are not case sensitive—For example, CREATE
TABLE, create table, and Create Table are all valid.
White space is generally ignored—This means you should use it to
make your SQL commands clearer.
The following example shows how to create the table for the
cd_collection database:
Click here to view code image
CREATE TABLE cd_collection
(
id INT NOT NULL,
title VARCHAR(50) NOT NULL,
artist VARCHAR(50) NOT NULL,
year VARCHAR(50) NOT NULL,
rating VARCHAR(50) NULL
);
Notice that the statement terminates with a semicolon (;). This is how SQL
knows you are finished with all the entries in the statement. In some cases,
you can omit the semicolon, and we point out these cases when they arise.
TIP
SQL has a number of reserved keywords that cannot be used in table names
or field names. For example, if you keep track of CDs that you want to take
with you on vacation, you cannot use the field name select because that
is a reserved keyword. Instead, you should either choose a different name
(perhaps selected) or just prefix the field name with an f, such as
fselect.