Page 07: Creating our first database table

Before soon we will need some data from the database to work with. The database we have is not very interesting since it's empty. To have something to work with in the next pages we will have to create some tables. The first one is regions.

database table : regions

A table that is connected to a lot of other tables is the regions-table. Since it won't bring in any values from other tables it's a good table to start with.

The regions-table will contain data on countries and regions and will later be used to set members nationality, regions for a specific title, switching navigation region on front-end, set release areas for list items and so forth. Needless to say it's a very important table. Create it with the following SQL-syntax:

CREATE TABLE `regions` (
`ID` INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT 'primary key',
`regionID` VARCHAR( 3 ) NOT NULL COMMENT 'ISO 3166-1 alpha-3 country code',
`regionName` VARCHAR( 100 ) NOT NULL COMMENT 'english region name',
`officialName` VARCHAR( 100 ) NULL COMMENT 'english official name of the country',
`tvSystem` VARCHAR( 20 ) NULL COMMENT 'TV Broadcast System (Analogue)',
`consoleRegion` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Boolean. Is it a console region?',
`titleRegion` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Boolean. Is it a title region?',
`countryRegion` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Boolean. Is it a country?',
`dateAdded` INT( 11 ) UNSIGNED NOT NULL COMMENT 'timestamp when added to db'
) ENGINE = innodb COMMENT = 'contain region data';

Let's discuss the various fields in the table:

Before we move on I would like to point out some crucial things about the naming and structuring of the database. There are a few conventions that needs to be followed, otherwise the database will conflict with some upcoming scripts with the result that the CMS won't work at all. Here are some rules that must be followed in order for the scripts to work properly:

Now that we have created a table we have something to work with. The table is still empty, but it's there. Now we can create the files needed to Create new rows in the table. So let's get to it:

Next Up: Initializing CRUD

<<-- INDEX
<<-- PAGE 06 PAGE 08 -->>