MySQL: UPDATING a row without a guaranteed unique field

I am working with an old MySQL table that serves as a sort log. He looks like

CREATE TABLE `queries` (
  `Email` char(32) NOT NULL DEFAULT '',
  `Query` blob,
  `NumRecords` int(5) unsigned DEFAULT NULL,
  `Date` date DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

Now I need to be able to UPDATEwrite to this table (don't ask why, I don't know). I usually just did

UPDATE table SET ... WHERE unique_column = value

But in this case, I do not have a unique column to work with.

Is there a workaround for this, or do I just need to click to add a good standard INT NOT NULL AUTO_INCREMENT?

+3
source share
5 answers
UPDATE queries 
SET ... 
WHERE Email = value1 
  AND Query = value2 
  AND NumRecords = value3 
  AND Date = value4 
LIMIT 1;
+3
source

A unique identifier is the only reliable way to do this. Just add a column auto_incrementand do with it.

, ( !) , OP .

. , : . - . , (, ), , , . , , , , .

+2

, , WHERE . , :

UPDATE queries
SET Query = 'whatever'
WHERE Email = 'whatever@whatever.com' AND
  Query = 'whatever' AND
  NumRecords = 42 AND
  Date = '1969-01-01'

, , ?

GUI MySQL Query Browser.

, , MySQL Query Browser.

0

. -, . , auto_increment. , , , , . , , ( ) .

0

. ( )?

, .

0

Source: https://habr.com/ru/post/1751823/


All Articles