你好, 我有问题.. 我正在使用Visual Studio 2008和ms sql server创建基于c# 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# 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!
更多推荐
重新安排数据表
发布评论