I know that the order in which a database stores data in a table is random – provided there is no primary key. My question is, fundamentally, what’s going on when the data changes order after a query? If one opened a database, closed it and opened it again to find the data in a different order, what’s going on when that happens?
Share
Its, probably, the question about realization – so it depends on what DBMS you’re using.
The simplest answer – data from this table gone out of DBMS cache and will be read from disk in arbitrary order, if not specified with explicit ORDER BY operator.
The main issue of non-existing primary key – the loss of data consistency. The only reason for table not to have primary key – when the table is a staging (buffer) table.