range - SQL statement to generate a column whose value is the record index -


I have some SQL table, one column says to C1:

  c1 Now, I would like to issue a SQL command (some of my DBMS operations, which I have not intentionally done) which causes the cause of my desk  

/ P>

  C1 record_ index ------------------- 10 0 3 1 1 2 10 3 5 4  

Very simple ... can this be done? Obviously, you do not already know the length of the table, so no SQL insertion or similar tricks.

Note: I want a general answer, but be specific - I am working with it. There is no such thing as "row indices" in the relational database (note that the lines in a relational database) Are not "records"), but if you can find a column that can be easily sorted by using a window function:

  by record_index__outx C1 as row_number () in the form of key_directory (order by some_column) Do not;  

(You have not specified your DBMS, above is ANSI SQL)

Edit

If you There is no column to sort on, you can try sorting instead of a constant value, which will bring the rows back "unordered":

  record_index, row_number () Select (42) by the_table command by order_table__andex;  

But again: there is no such thing as the "natural" order of the rows; there can be be on the disc, but having it the most Is unlikely to be used during recovery - especially when there is no package index in the table (Oracle does not use a package index by default, postgrads do not have at all).

A DBMS can also apply additional customization when the data is recoverable Oracle, Postgrease and I believe that the SQL Server as well as the "hop" disc on a table Regularly scans from a different session to read the static. In that case, two concurrent selections will show a different "order" even if the phyiscal layout on the harddisk has not changed.

And after that you can make changes to the physical stock due to the update (for example, if a row is not fit on the block at any time because its size increases).


Comments