Programare & stuff > Programare

mysql stuff

(1/1)

Admin:
//

 CREATE TABLE counters(
     id INT NOT NULL UNIQUE,   -- multiple counters can be stored in this table, this is its id
     value INT                            -- current value of the counter
  );
 
  -- Initialize the first counter with start value 10
  INSERT INTO counters VALUES (1, 10);
 
  -- Let's get the current value
  SELECT value FROM counters WHERE id = 1;
 
  -- Increment the counter
  UPDATE counters SET value = value + 1 WHERE id = 1;

//

START TRANSACTION;
 
  -- Let's get the current value
  SELECT value FROM counters WHERE id = 1 FOR UPDATE;
 
   -- Increment the counter
  UPDATE counters SET value = value + 1 WHERE id = 1;
 
  COMMIT;

//

UPDATE counters
SET value = (@cur_value := value) + 1
WHERE id = 1;

//

UPDATE counters
SET value = LAST_INSERT_ID(value) + 1
WHERE id = 1;

Navigare

[0] Indexul de Mesaje

Du-te la versiunea completă