MySQLAdmin程序运行代码两次

时间:2016-12-23 04:27:30

标签: mysql stored-procedures

我正在使用MySQLAdmin。我有一个过程将一个新行插入一个表,但它没有添加一次,而是两次。这是程序:

CREATE PROCEDURE add_game(IN game_name VARCHAR(50), IN game_price DOUBLE) 
BEGIN
  INSERT INTO games (id, name, price) VALUES (NULL, game_name, game_price);
  SELECT * FROM games;
END

SELECT * FROM games;

| id | name     | price |
|----|----------|-------|
|  1 | chess    | 12.95 |
|  2 | life!    | 10.55 |
|  3 | checkers | 10.55 |

CALL add_game('jacks', 3.69);

| id | name     | price |
|----|----------|-------|
|  1 | chess    | 12.95 |
|  2 | life!    | 10.55 |
|  3 | checkers | 10.55 |
|  4 | jacks    |  3.69 |
|  5 | jacks    |  3.69 |

为什么会这样做?

更新:

当我将name列更改为唯一时,我收到一条错误消息:

Error
SQL query:


CALL add_game('chess', 5.98)
MySQL said: Documentation

#1062 - Duplicate entry 'chess' for key 'name'

0 个答案:

没有答案