0

What is the best way to generate a primary key in the following table structure? Using MySQL 5.6 community.

PosDateTime varchar(24)
Model varchar(5)
Hour Int(11)
Lat double
Lon double
Wind Int(11)
Pres Int(11)

There will be many instances of each of these fields containing the same value throughout the table, but there will not be a record that is exactly identical (at least one field will be different). So if I'm not mistaken, I can't use any of these fields as a Primary Key because of duplicates, right??

This table will have up to about 50,000 records. Currently, before I insert into the table, I check to see if the record already exists, then do the insert if it's not there, it takes a little longer because I do not have a primary key setup. I'll also need to search on the table to get values.

Should I use a composite primary key using all fields?

This table will not relate to other tables in any way. Thanks for your input. Bryan

Alma Do
  • 37,009
  • 9
  • 76
  • 105
Bryan
  • 81
  • 2
  • 8
  • 1
    The definition of a primary key is that it MUST be unique so you can identify a given row. If the values are not unique they can't be a primary key. Now you can have a primary key that consists of more than one column. That is known as a composite key. Also, you should only tag the relevant DBMS that you are using. sql server <> mysql. – Sean Lange Jul 17 '15 at 14:53
  • @AlmaDo I did see that post before submitting my question, but to me it's talking about 2 tables and how they relate to each other. I just have a single table. I'm new at this, so maybe there is something with the other post I'm not getting. So, is a composite key the way to go? – Bryan Jul 17 '15 at 15:07

0 Answers0