<<I like to sort tables frequently  (LastName,FirstName,etc.) so that we don't 
always have to add an ORDER BY  clause.  Just lazy, I guess.  This is probably 
not great practice  but...

  >>



That's putting it mildly!



If you always want the data sorted the same way, RBase offers an extension to 
standard SQL that will let you do it and never have to worry about sorting the 
data again.  You can use ORDER BY with a view.  To refactor an existing 
database to keep the CUSTOMER table sorted automatically, do this:



RENAME TABLE Customer TO Customer_Raw NOCHECK



CREATE VIEW Customer AS SELECT * FROM Customer_Raw ORDER BY LastName, FirstName



You now have a fully editable single table view called Customer which looks 
_exactly_ like the customer table but will always appear in name order.  You 
can insert, update, and delete from Customer as if it were a table, or you can 
perform those actions directly on Customer_Raw, but Customer will always give 
you the sorted customers.



You'll take a slight performance hit for this, but not as big a hit as 
constantly having to rebuild the table or missing records because they got out 
of sequence.

--

Larry


Reply via email to