重新安排数据表 [英] re-arranging the datatable

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

问题描述

你好,
我有问题..
我正在使用Visual Studio 2008和ms sql server创建基于c#.net Windows的项目.
我想在删除后重新排列我的数据表.
我正在解释...
(1)我有一张州代码表,州名,年份.
如果我从所有状态中删除1个状态,则应重新排列状态代码.
就像状态码1,2,3,4,5.和我删除第4行,则它变成1,2,3,5.
我希望它是1,2,3,4.means从1开始的4条记录.

(2)如果我不将状态码用作主键,那么
是什么 解决此问题的方法.

请回复.

hello,
i have a problem..
i am creating c#.net windows based project using visual studio 2008 and ms sql server.
i want to rearrange my datatable after deletion.
i am explaining it...
(1) i have a table of Statecode,statename,year.
if i delete 1 state from all states,then statecode should be re-arrange.
as if statecode 1,2,3,4,5.and i delete 4th row then it becomes 1,2,3,5.
i want it to be 1,2,3,4.means 4 records starting from 1.

(2) if i will not take statecode as a primary key,then what is the
solution for this problem.

please reply.

推荐答案

khandelwal g写道:
khandelwal g wrote:

我希望它成为1 ,2,3,4.表示从1

i want it to be 1,2,3,4.means 4 records starting from 1


开始的4条记录
你为什么要这么做?有什么需要吗?不建议这样做.通常,应用程序不适用于单个表.有依赖关系和外键关系.如果更改主表中的从属列值,则还需要注意其他表.

重新分配值没有意义.它们在数据库中,您的应用程序知道如何处理它.

实际上,大多数时候,主键都被用作身份键,以避免出现任何问题.




Why do you want to do that? What''s the need? It''s not advisable. Generally applications does not work on single table. There are dependencies and foreign key relations. If you change a dependant column value in main table then you need to take care of other tables too.

There is no point in re-assigning the values. They are in DB and your application knows how to handle it.

Infact, primary keys most of the times are made an Identity Key to avoid any issue.


khandelwal g写道:
khandelwal g wrote:

如果我不将状态码用作主键,那么什么是
解决此问题的方法.

if i will not take statecode as a primary key,then what is the
solution for this problem.


我在这里没发现任何问题吗?麻烦您什么了?重新排列不会帮助您,为什么要这么做!


I don''t find any problem out here? What''s troubling you? Rearrangement is not going to help you, so why to do it!


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

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