查詢創建表:重複條目在MySQL的關鍵 「主」
create table if not exists person ( roll_no int(4) AUTO_INCREMENT primary key, name varchar(25), city varchar(25));
查詢設置起始號碼自動遞增的主鍵:
alter table person auto_increment = 1;
查詢插入數據:
insert into person (name,city) values("Maxwell", "Pune"); insert into person (name,city) values("Baldwin", "Bengaluru"); insert into person (name,city) values("Novartis", "Paris"); insert into person (name,city) values("Shaun", "Mumbai"); insert into person (name,city) values("Beckham", "Toronto"); insert into person (name,city) values("Ashish", "Bengaluru"); insert into person (name,city) values("David", "Paris"); insert into person (name,city) values("PK", "London"); insert into person (name,city) values("Chris", "Bengaluru"); insert into person (name,city) values("Aston", "Mumbai");
查詢刪除的行:
delete from person where roll_no=5;
表STR刪除一行之後ucture:
roll_no name city 1 Maxwell Pune 2 Baldwin Bengaluru 3 Novartis Paris 4 Shaun Mumbai 6 Ashish Bengaluru 7 David Paris 8 PK London 9 Chris Bengaluru 10 Aston Mumbai
現在,一邊尋找恢復已刪除的行,編譯拋出錯誤所用「Duplicate entry '5' for key 'PRIMARY'
」
查詢重新設置已刪除的行。
update person set roll_no = roll_no + 1 where roll_no >=4 order by roll_no desc; insert into person (roll_no, name, city) VALUES (5, "Beckham", "Toronto");
可能是什麼這個問題的可能原因是什麼?強烈建議任何輸入。
只是刪除更新語句.. – amdixon
是什麼表的樣子後,更新,但其之前插入?看到?真的很簡單。 – Strawberry
@amdixon - 美麗......解決了這個問題,但仍然無能爲力,爲什麼更新查詢造成了問題?你能解釋一下嗎? – mindfreak