Basic How-To Example of a MySQL CREATE TABLE command

Here’s a basic example of a MySQL CREATE TABLE command.

CREATE TABLE `foo`.`example_01` (
`field_1`         VARCHAR(255),
`field_2`         CHAR(10),
`field_3`         INT(10),
`field_4`         BIGINT(20),
`field_5`         DATETIME

Notice that the ‘back tic’s on each column definition (the little ` characters) are optional in most cases. I use them for reasons I’ll discuss later on.

Also, for most columns you see a number in parentheses after the name of the type — that is the default size for displaying that value in a select statement.

The actual size of the value you store in that column isn’t impacted by changing that number. Changing INT(10) to INT(12) won’t change the size of the data you can store in that column.

Click here to go to the table of contents for all MySQL Programming Example Code
This entry was posted in mysql and tagged , , . Bookmark the permalink.
  • Raytop4real

    Hi,please i need help with the syntax for creating appointment table with attributes(appno INT(10)unique,appdate,applength,apptime,custID INT(10),staffID INT(10)); please its urgent thanks.

    Current score: 0