Dilema将增量数字添加到我的表中 [英] Dilema adding incremental numbers to my table

查看:54
本文介绍了Dilema将增量数字添加到我的表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我有一个表,我正在尝试向一组特定的列中添加一个自动增量(如数字集).

我正在使用C#VS2010,并使用oledb建立与表的连接.我可以连接到表,但无法弄清楚完成此工作所需的SQL代码.

我正在使用的表除外,它看起来像这样

说明简短描述ID
希思罗机场LHR
哈利法克斯YHZ
洛杉矶国际机场

我意识到我相信我必须使用更新语句.我已经尝试了一切.我什至创建了一个表,其编号为50-150,并且我试图将两者合并,但我无法弄清楚.

如何使我的桌子看起来像这样?

说明简短描述ID
希思罗LHR 50
哈利法克斯YHZ 51
洛杉矶LAX 52
53
54

我正在尝试使ID计数到150,即使Description或ShortDescription中没有任何内容.

如何在空白列中添加从50开始到150停止增加的数字,即使其他列中没有任何内容,也要增加数字?有没有一种使用SQL Update语句的方法,还是使用数据集合并或其他方法会更好?我无法更改表结构以添加autoNumber数据类型.

预先感谢.

Hello All

I have a table that I''m trying to add an auto-increment like set of numbers to a specific column.

I''m using C# VS2010 and using oledb to make the connection to the table. I''m able to connect to the table but I''m not able to figure out the SQL code needed to make this work.

I''ve got an except of the table that I''m working with and it looks like this

Description ShortDescription ID
Heathrow LHR
Halifax YHZ
Los Angeles LAX

I realize that I believe that I have to use an update statement. I''ve tried everything. I even created a table that has numbers of 50-150 and I''ve tried to merge the two but I couldn''t figure that out.

How do I get my table to look like this??

Description ShortDescription ID
Heathrow LHR 50
Halifax YHZ 51
Los Angeles LAX 52
53
54

I''m trying to get the ID to count up to 150 even if there''s nothing in Description or ShortDescription.

How do I add the numbers to increment starting from 50 and stoping at 150 in a blank column and to increase even if there''s nothing in the other columns? Is there a way using an SQL Update Statement or would it better to use dataset merge or something else? I''m not able to change the table structure to add autoNumber datatype.

Thanks in advance.

推荐答案

1.如果您要使用自动递增",请在表中"中选择ID.从列属性标识种子递增(是)(起始编号)递增(要递增的编号)
2.如果要添加空值,也只需留下ID(而不是将其作为主键)
3.如果您要PK并希望增加并且希望具有空行,则在数据库中创建另一个字段,其名称为ID2,并将第一个ID设置为PK和Increment
和ID1只能导致罪魁祸首

我想如果您需要任何帮助注释会有所帮助
1.If you want the Auto Incriment select ID in your Table From (you are using Oledb i think its Access) From Access and Select Auto Increment to Yes from Column Properties Identity seed (starting Number) Increment(which number to Incriment)
2.If you wanted to add null values also Simply Leave ID (not put it as Primary Key)
3.If you want PK and Wanted to increment and Wanted to Have null rows then create another Field in Database with the Name of ID2 and Put First ID as PK and Increment
and ID1 to only incriment

I think this will help if you want any help comment


据我所知,您需要这样的东西(我为您的表机场命名,并假设您的表中正好有150行):

As I understood you need something like this (I named your table airports and assumed that you have exactly 150 rows in your table):

select b.Description, b.ShortDescription, 
	ROW_NUMBER() OVER(order by shortdescription desc) +49 AS 'ID'
	from airports b 



如果您需要修改,请为我提供更多详细信息,以提供其他解决方案;)



If you need modifications please express more details for me to provide another solution ;)


这篇关于Dilema将增量数字添加到我的表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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