Rouven: MAX(id) klappt nicht!

Beitrag lesen

Hi,

INSERT INTO Tabelle1 (id, spalte1, spalte2) VALUES ( (SELECT MAX(ID) FROM Tabelle2), 'Wert1','wert2')

super Vorschlag. Ich würde sagen das gibt bei einem normalen Datenmodel ein "Duplicate entry for index ...", weil du die selbe ID nochmal vergibst. Rechne bitte wenigstens eins drauf.

Ansonsten: Hendrik, warum machst du dir die Mühe ein Konstrukt von Hand zu erzeugen, was eigentlich schon da ist. Auto_Increment unterstützen fast alle Datenbanken auf die ein oder andere Weise ab Werk, dann brauchst du auch keine freien Werte zu suchen oder sonstwas.

MfG
Rouven

--
-------------------
Computer programming is tremendous fun. Like music, it is a skill that derives from an unknown blend of innate talent and constant practice. Like drawing, it can be shaped to a variety of ends: commercial, artistic, and pure entertainment. Programmers have a well-deserved reputation for working long hours but are rarely credited with being driven by creative fevers. Programmers talk about software development on weekends, vacations, and over meals not because they lack imagination, but because their imagination reveals worlds that others cannot see. -- Larry OBrien and Bruce Eckel in Thinking in C#