Information générale
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Assuming that the table has an unique index on the Id_Nr field of the table, we usually do the following:
Sele Mytable && The table you are about to update
set orde to Unique_Index && A unique index
go bott && Get the highest number
stor Id_Nr+1 to mnewnr && Add 1 to it
INSE INTO Mytable (Id_Nr) valu(mnewnr) && Insert the new number
If the Id_Nr field is a character type, use the following:
Sele Mytable && The table you are about to update
set orde to Unique_Index && A unique index
go bott && Get the highest char number
stor STR(VAL(Id_Nr)+1,4) to mnewnr && Based on a 4 char field
INSE INTO Mytable (Id_Nr) valu(mnewnr) && Insert the new number
Keep in mind that if you use a character field for the Id or Reference number of a table, you should always start at a number like 100, 1000, 10000, etc. If you start at a blank the index will display the records incorrectly.
Hope it helps... :)
Précédent
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement