diff options
| author | Walter Pagani <paganiwalter@gmail.com> | 2022-07-02 12:28:06 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-02 17:28:06 +0200 |
| commit | a9a9f546343324f5b78298d273ad6c410aa2a29e (patch) | |
| tree | a8cb9a30ab692deb267a77bec79552d9d61e6fe6 /docs | |
| parent | 630aa0e2af0b28a7295cf41d3d01e9352d624107 (diff) | |
| download | wiki-a9a9f546343324f5b78298d273ad6c410aa2a29e.tar.gz wiki-a9a9f546343324f5b78298d273ad6c410aa2a29e.tar.bz2 wiki-a9a9f546343324f5b78298d273ad6c410aa2a29e.zip | |
Add (Translation\ES): how-to-obtain-free-records (#752)
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/es/how-to-obtain-free-records.md | 73 | ||||
| -rw-r--r-- | docs/how-to-obtain-free-records.md | 2 |
2 files changed, 75 insertions, 0 deletions
diff --git a/docs/es/how-to-obtain-free-records.md b/docs/es/how-to-obtain-free-records.md new file mode 100644 index 0000000..76a6552 --- /dev/null +++ b/docs/es/how-to-obtain-free-records.md @@ -0,0 +1,73 @@ +--- +redirect_from: "/es/how-to-obtain-free-records" +--- + +# Cómo obtener registros libres + +En algunas ocasiones, necesitamos obtener o conocer registros cuyos valores no están siendo ocupados. + +Ya sea porque queremos insertar un nuevo valor, o porque queremos reestructurar nuestra tabla después de un tiempo. + +Para ello, puede utilizar el siguiente script: + +```sql +SELECT t.id + 1 +FROM Table1 t +WHERE NOT EXISTS ( + SELECT * + FROM Table1 t2 + WHERE t2.id = t.id + 1 +) +LIMIT 1 +``` + +Debemos sustituir el nombre de la tabla, y los atributos que buscamos. + +Ahora veamos un ejemplo. Supongamos que queremos buscar el primer registro libre dentro de `creature`. + +Lo primero que tenemos que identificar es su clave primaria: `guid`. + +```sql +SELECT t.`guid` + 1 +FROM `creature` t +WHERE NOT EXISTS ( + SELECT * + FROM `creature` t2 + WHERE t2.`guid` = t.`guid` + 1 +) +LIMIT 1 +``` + +Al ejecutar la consulta, obtendremos como resultado en este caso, el número **15**. + +**Nota:** Actualmente el valor cambio, y ahora es otro. Pero en su momento era el numero 15. + +Lo que debemos hacer ahora es comprobar que este valor no se está utilizando, mediante un `SELECT`. + +```sql +SELECT * FROM `creature` WHERE `guid`=15; +``` + +Para corroborar que la información es correcta, les dejamos los 16 primeros registros. + +| guid | id | map | zoneId | +|------|-------|-----|--------| +| 1 | 2843 | 0 | 0 | +| 2 | 7853 | 0 | 0 | +| 3 | 2499 | 0 | 0 | +| 4 | 2838 | 0 | 0 | +| 5 | 2839 | 0 | 0 | +| 6 | 2626 | 0 | 0 | +| 7 | 2482 | 0 | 0 | +| 8 | 8123 | 0 | 0 | +| 9 | 9459 | 0 | 0 | +| 10 | 9520 | 0 | 0 | +| 11 | 1215 | 0 | 0 | +| 12 | 1218 | 0 | 0 | +| 13 | 30140 | 571 | 0 | +| 14 | 30156 | 571 | 0 | +| 16 | 32442 | 571 | 0 | + +Como puede ver, el número 15 está disponible. + +**Note:** la tabla tiene muchos más atributos, pero sólo mostramos algunos, para que la tabla no sea tan extensa. diff --git a/docs/how-to-obtain-free-records.md b/docs/how-to-obtain-free-records.md index 36ed335..e7a4c91 100644 --- a/docs/how-to-obtain-free-records.md +++ b/docs/how-to-obtain-free-records.md @@ -40,6 +40,8 @@ LIMIT 1 When running the query, we will get as a result in this case, the number **15**. +**Note:** Currently, the value has changed, and now it is different. But at the time it was number 15. + What we must do now is to check that this value is not being used, by means of a `SELECT` ```sql |
