1

Is there is a way. I can save my table in ascending order by id.

I want to create new table from existing table for that I am using. SELECT id,name into newtable from oldtable order by id asc. So it create the table but new table doesnot store in ascending order by id. I want to store the id in ascending order in new table.

SELECT AirlineData2019.[id]
      ,AirlineData2019.[DestAirportID]
      ,AirlineData2019.[DestAirportSeqID]
      ,AirlineData2019.[DestCityMarketID]
      ,AirlineData2019.[Dest]
      ,AirlineData2019.[DestCityName]
      ,AirlineData2019.[DestState]
      ,AirlineData2019.[DestStateFips]
      ,AirlineData2019.[DestStateName]
      ,AirlineData2019.[DestWac] 
 INTO Destination FROM AirlineData2019 ORDER BY id;
```[![I want to save my data in that way in new table][1]][1]


  [1]: https://i.stack.imgur.com/c0h0t.png

2 Answers2

1

SQL tables represent unordered sets. So storing them in an "order" doesn't really make sense. Actually, most databases support clustered indexes, which do have an ordering.

But even with a clustered index, this does not do what you want -- because queries on the table are not guaranteed to return the results in a particular order unless you use an order by.

I would recommend that you define the id column as the primary key -- or at least create an index on it. Then when you use order by id, the query will use the index.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
0

The short answer - no.

SQL tables are inherently unordered. If you want to retrieve the rows in some particular order, you'll just have to use an order by clause when you query it (like your original query did).

Mureinik
  • 297,002
  • 52
  • 306
  • 350