C#数据库重新排序 [英] c# database reordering

查看:231
本文介绍了C#数据库重新排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看看我是否有这样的数据库

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


现在,当我添加另一条记录Dealer Agra 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


应在不使用自动ID的情况下实现

请帮助我.


This should be achieved without using auto id

Please help me.

推荐答案

我认为这不是一个好主意.

从数据库中获取数据时应进行排序,而不是在数据库中插入数据时进行排序.插入时,只需确保插入所有相关数据即可满足不同类型的订购需求.

如果您将订单放入表中,那只是一种变化.如果需要另一种订购会怎样?

要获取所需的结果,您应该在选择中对结果进行排序,例如:
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:
SELECT Category, City, ROW_NUMBER() OVER(ORDER BY City)
FROM YourTable
ORDER BY City


这篇关于C#数据库重新排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆