SQL to reorder the table Main_Table by field DteTme

  • I want to reorder my table by DteTme and save everything back into the same table which is Main_Table. Does anyone know what the SQL would be to do that?

  • Read this article on SSC

    Sorting Months By Number (SQL Spackle)

    By Jeff Moden, 2010/11/15

    Here is the link to the article:

    http://www.sqlservercentral.com/articles/T-SQL/71511/

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

  • I'm reading it right now. It is a bit over my head though. I'm not quite that advanced yet. I see you can use ORDER BY but I don't really see how I can ORDER BY and stuff everything back into the same table.

  • sql doesn't really need the data in a specific order; you should typically just use an order by when you need the data in a specific order.

    it uses indexes to find the data.

    technically the data in a table is stored in the same order as the clustered index of the table. so if you did a table with a typical "int identity(1,1) not null primary key", that column is the order the data is stored, because unless you tell it otherwise, SQL assumes the primary key is the best candidate for the clustered index when you build the table

    so if you REALLY wanted to store the data in the order of your date column , you would want to drop the clustered index and create a new one.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply