我正在使用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'