» MySQL Table Advise by Admin |
|
(Login to remove green text ads)
So your all set up to create your first dynamic website and you plan on using MySQL to store all your sites data, nice choice.
Here are a couple pointers on creating your table.
- Define your datatypes correctly.
- Name the table something easy to remember.
- Name the columns something easy to remember.
1. *Primary Key* A primary key will keep all your rows of data unique. This will make it much easier to maintain your data later on. If you fail to use a primary key data corruption when updating your site is likely.
create table key_example (id int(6) not null auto_increment, more table definitions here, primary key(id));
This table is using 'id' as the primary key. Setting up the primary key as an int and using auto_increment make this a very easy way to use a primarty key.
2. *Datatypes* Defining all datatypes correctly will allow you to use the data with all programming languages. Setting a column to a number type will allow you to run math operations on those values. Failure to do this may cause more work for you later, so just define your fields properly.
3. *Table Name* Naming your table something relevent to what the data is used for will help you out when you have 40+ tables in a single database. I dont know how many times I have had to ask other developers what they named a table for a specific job because they named it something like 'XYZ123'. This will save headaches when you are working on large scale projects
4. *Column Names* See Table Name above.
|
|