Creating a table

At this point, you should now be logged into MySQL with ALL privileges granted for the database publications (or a database that was created for you)—you’re ready to create your first table. So make sure that database is in use by typing the following (replacing publications with the name of your database if it is different):

USE publications;

Now enter the commands in following Example one line at a time:

CREATE TABLE classics (
author VARCHAR(128),
title VARCHAR(128),
type VARCHAR(16),

MySQL should then issue the response “Query OK, 0 rows affected,” along with how long it took to execute the command. If you see an error message instead, check your syntax carefully. Every parenthesis and comma counts, and typing errors are easy to make. In case you are wondering, the ENGINE MyISAM tells MySQL the type of database engine to use for this table.
To check whether your new table has been created, type:

DESCRIBE classics;

The DESCRIBE command is an invaluable debugging aid when you need to ensure that you have correctly created a MySQL table. You can also use it to remind yourself about a table’s field or column names and the types of data in each one. Let’s look at each of the headings in detail:

Field The name of each field or column within a table.
Type The type of data being stored in the field.
Null Whether a field is allowed to contain a value of NULL.
Key MySQL supports keys or indexes, which are quick ways to look up and search for data. The Key heading shows what type of key (if any) has been applied.
Default The default value that will be assigned to the field if no value is specified when a new row is created.
Extra Additional information, such as whether a field is set to auto-increment.

You may also like...