Groups | Blog | Home
all groups > sql server (alternate) > february 2004 >

sql server (alternate) : Sorting via script


Kelly Mayo
2/21/2004 11:15:46 PM
I have a movie db in sql 7 that I like to keep sorted by title. I have been
exporting to another table, and sorting output by title, then deleting the
original table and renaming the new table to the old tablename.

I would love to script this but dont know how to rename a table. I can drop
and create via script, but thats it. Any help appreciated...

There is probably a better way to do this but I dont know it. Of course I
could always sort during the query but I like to have it presorted.

Thanks,

Kelly

mountain man
2/22/2004 3:45:17 AM
[quoted text, click to view]


Have a look at sp_rename (table).

The sort order specified in a query script
does actually work every time.






John Bell
2/22/2004 8:05:19 AM
Hi

I am slightly confused by this, as you seem to think that the data in the
new table is sorted! The only way you can guarantee an order for data
returned by a query is to specify an ORDER BY clause.
What you may require is to reindex or defragment the indexes on your table,
but this will not guarantee order.

John

[quoted text, click to view]

Dandy WEYN
2/23/2004 2:52:05 AM
exactly the only way to retrieve the data in the correct order is by using
an order by clause, so you have no need on recreating the table and import
them with an order by clause.


--
Dandy Weyn, Belgium
MCSE, MCSA, MCDBA, MCT

http://www.dandyman.net

Check my SQL Server resource pages (currently under construction)
http://www.dandyman.net/sql


[quoted text, click to view]

AddThis Social Bookmark Button