In SQL, while inserting into a presorted table, is it possible to insert a row while sorting the row along with the entire table? Such as
create table positional_order (
num number,
txt varchar2(10)
);
existing table
row 1 (3, 'three' );
row 2 (4, 'four' );
insert a new row
row 3 (1, 'one');
after the insert
table becomes
row 1 (1, 'one');
row 2 (3, 'three' );
row 3 (4, 'four' );
Is this possible?
Or I have to insert the row into the table and then do select order by ?
Btw I am using sqlite.
Thanks,
As far as I know inserting a row into a particular location is not part of any standard SQL database. Part of the database's job is to determine how to logically store rows. As you said, the time to order rows is when you do the SELECT, using ORDER BY.
If you are concerned about performance, create an index on the 'number' column. More on indexes here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With