----- Original Message ----- From: "DBS" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Sunday, November 21, 2004 7:37 AM Subject: Primary key error
> Hi list, > > MySQL newbie here and am using Navicat to learn how to manage a database for > a test OS shopping cart. I got the below error message after importing a > table into the database. Can anyone tell me what I could do to correct the > problem? Would I need to add an additional column to the table in question > for the primary keys, one for each row entry? > > "Zen_products does not have a primary key. Updates to this table will be > done using the following pseudo statement: > UPDATE zen_products SET ModifiedFieldsAndValues Where > "AllFieldsAndOldValues" > Updates to a record in this table may update more than one record." > You may not need to add any columns to the table, although I can't say for sure since you don't provide a definition of the existing table or describe the data in it. MySQL or Navicat wants your table to have a primary key, which it apparently doesn't have. The good news is that you can add a primary key to an existing table, even after it has data in it. The primary key definition can identify a single column or a combination of columns as the primary key. Here are examples of both: alter table mytable add primary key (id); alter table mytable add primary key(area_code, phone_number); You need to look at your table definition and choose a column or combination of columns that uniquely identifies each row in the table. Then write and execute the appropriate ALTER TABLE statement. If the ALTER TABLE statement works, it should prove that your analysis was correct and you have chosen an appropriate column or columns as the primary key; if the ALTER TABLE fails, it will probably be because you have analyzed the data incorrectly and chosen something that isn't unique for the data in the table. If you can't find a unique column or combination of columns in your column, you may have to add an additional column or columns to the table to ensure that a primary key is possible on the table, then add the primary key via the ALTER TABLE statement. Choosing a good primary key is a non-trivial task; if you have no experience with data modelling, particularly normalization, you should get some help from someone who has this experience. It is not particularly hard to do but if you have no experience, it is difficult to explain briefly how to do it in a way that you are likely to understand. If you have no one to help you, you can try posting a detailed description of your data and perhaps someone on this mailing list can help you figure out the best primary key for your data. Rhino -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]