sqlwrite does not preserve row order

7 views (last 30 days)
I am writing a script to manipulate a .mat file containing a structure into a table and then write to a Microsoft SQL Server database. When I use the sqlwrite command, it does not seem to preserve the row order of the original table. The columns are all there and rows are written correctly, but the starting point is different every time I delete and rewrite the table. This is annoying as the data should be ordered by increasing time. Is there a way to preserve order when writing?
Thanks in advance for any help!

Accepted Answer

the cyclist
the cyclist on 9 Mar 2023
Even if you store the data in a particular order (which you should not try to do), there is no guarantee that any given SELECT statement will retrieve the data in that order. I know for a fact that this is true in PostgreSQL, and I am confident that this is true in the major databases systems.
Users who need records in a particular order must use the ORDER BY clause (or equivalent).

More Answers (0)

Products


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!