SQL Server Order Allocation

Asked

Viewed 41 times

0

It is possible for me to relocate this latest product with ID 21, to the field I have drawn in red?

dados


Actually, look at that. It is not by TOC, but something functional, in our site where it is taking as reference the bank, this showing as it is in the bank, and therefore the need to organize pro segments. This last product was inserted after the completion of the other inserts, so it is not segmented. I have an nmOrder column that is ordered correctly but still wrong.

inserir a descrição da imagem aqui

  • It’s not just ordering from the field stProduto or I didn’t understand your doubt?

  • but the problem that is already at the base, and that basis it points to a product site and I needed that last product to stay together with his segment of toilet paper

  • It seems to me, since you have not provided the proper information, that the field id It’s kind of self-improvement. Whoever created the database used this type of field (artificial key) so as not to worry about any specific order of record storage. Incidentally in any DBMS if you want to ensure data recovery in any particular order should always use the clause ORDER BY.

1 answer

1

It is possible, but not recommended. To do this would have to change the id and that’s something you shouldn’t do, you’d have to change the id of several other data lines, and in a certain scenario of all. And then all references to these data would be invalid. It would have to change in every database, application, or anything external that has picked up this reference by id. So don’t do it, let it be good.

Note that you cannot organize how the database puts information inside it, it is not your interest, it is implementation detail and it can change as you wish.

What I think you’re thinking is that this data is organized the way you see it. This is just a presentation, an application that shows data, she decided it would show like this, she must have other ways of showing it in other ways.

You can have it shown differently right there or elsewhere. This presentation probably came from a query SQL, and what you’re describing would have to do something like:

SELECT FROM Produtos ORDER BY stProduto

I kicked the name of the table. Ready, is presenting the way you want. But no reallocation was made. To reallocate could make a script classification (Sort) that record the data and not only present it, but have all the problems I said before.

The need to put everything together doesn’t make sense and it’s not how a database works. The will to do this must happen either by not knowing the nature of the database or by having OCD, which I understand, but should not yet do, not being the first.

Of course if the table has just been created and there is no reference to it anywhere inside or outside the database would even do that Sort to meet this taste, but always something like this will occur and can not do the other times, so better not waste time, focus on the presentation.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.