Click here to Skip to main content
15,906,567 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
See if I have a database like this
Table Headers    Category  City  Serial_no

Table Content    Dealer    Agra     1
                 Dealer    Agra     2
                 Dealer    Chennai  3

Now when I add another record Dealer Agra 3, then the table content should change to
Dealer    Agra     1
Dealer    Agra     2
Dealer    Agra     3
Dealer    Chennai  3

This should be achieved without using auto id

Please help me.
Posted
Updated 5-Sep-11 20:57pm
v2

1 solution

In my opinion this is not a good idea.

Ordering should take place when you fetch the data from the database not when you insert data in it. When inserting you just make sure that you insert all relevant data for different kinds of ordering needs.

If you put the ordering into the table, it's just one variation. What happens if another kind of ordering is needed.

To fetch the desired results you should order the results in the select, something like:
SQL
SELECT Category, City, ROW_NUMBER() OVER(ORDER BY City)
FROM YourTable
ORDER BY City
 
Share this answer
 
Comments
Toniyo Jackson 6-Sep-11 3:09am    
Correct, 5!
Wendelius 6-Sep-11 3:11am    
Thanks Toniyo :)
Mehdi Gholam 6-Sep-11 3:20am    
Couldn't have said it better. 5
Wendelius 6-Sep-11 3:36am    
Thank you :)
hilmisu 6-Sep-11 3:59am    
i agree with that solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900