Jump to content

Should I use the date/time as the key


cmor

Recommended Posts

Although most of you have probably made hundreds I'm about to attempt my first mysql database.  I'm attempting to build a database of weather data from the page:

 

http://www.nwac.us/products/OSOCMT

 

It will compile each days weather and save it sequentially. I've already done it in a flat file and am working my way up to a mysql database. Currentlly it looks something like this:

 

7 11 600 64 57 69 8 13 17 96

7 11 700 67 60 65 7 12 18 103

7 11 800 70 65 53 8 13 18 106

7 11 900 73 70 47 5 11 18 110

7 11 1000 75 76 42 0 7 15 121

7 11 1100 75 80 29 0 5 12 111

7 11 1200 76 84 23 0 3 12 84

7 11 1300 78 87 24 0 3 9 158

7 11 1400 77 87 23 0 2 8 197

7 11 1500 81 86 28 0 2 10 221

7 11 1600 86 83 36 0 3 10 346

7 11 1700 89 81 40 0 4 11 334

7 11 1800 83 77 46 0 5 14 323

7 11 1900 79 70 66 0 5 11 324

7 11 2000 65 67 69 0 4 9 343

7 11 2100 64 63 70 5 8 11 338

7 11 2200 64 62 67 5 7 9 347

7 11 2300 64 61 70 4 7 10 5

 

Where the first column is the month, next coloumn day, next coloumn hour, and then the data.

The book I'm reading says databases search much faster when using the key as the search function.

My question is does it make more sense to make the key as a normal 1,2,3,4.

Or should I make it something like 7112300,7112400,7112500, etc. corresponding to each hour time frame.

 

When I search through the database I will almost always be searching by time frame and grouping the data into days.

So would it be quicker to search through keys that have the inherent date and time in them?

 

Thanks for any help.  I don't have the foresight to see what it will be like down the road. 

 

-Chris

Link to comment
Share on other sites

Most people automatically use an auto increment integer for their primary key.  If you will only ever have one entry for each date+time combo, then you should be able to use this as your primary key.  Remember, once you define it as a primary key, you won't be able to store two identical values, so if you'll ever have two events at one time, you'll need to use another column (such as an autoincrementing integer).  Use a DATETIME column type for that data instead of a column for hour, day, etc (if you didn't already know that).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.