现有表上带有nu唯一字段的SQL主键 [英] SQL Primary Key Required on existing table with nu unique field

查看:61
本文介绍了现有表上带有nu唯一字段的SQL主键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个SQL表,上面有大量数据.没有主键,并且表上没有唯一字段.

我复制了结构和一些数据,并能够通过设计添加主键字段,但是当我在原始表上尝试相同时,它会超时.

我知道的唯一另一种方法是添加一列,手动填充字段,然后设置键,但是有超过一百万条记录.

请问还有另一种方法吗?

Hi,

I have a SQL table with a large quantity of data on it. There is no primary key and there is no unique field on the table.

I copied the structure and some data and was able to add a primary key field through design, but when I try the same on the original table it times out.

The only other way I know would be to add a column, populate the field manually and then set the key, but there are over a million records.

Is there another way of doing this please?

推荐答案

我不是100%肯定需要的T-SQL,但是可以创建自己的T-SQL.带有主键的新表,然后在旧表上运行光标,将在旧表中找到的每一行插入到新表中
I''m not 100% sure of the T-SQL you''d need, but you could create your new table complete with primary key and then run a cursor over your old table, inserting each row you find in the old table into the new one


另一种方法可能是创建一些新表表,每个表都有自己的主键,然后将数据从现有表复制到其他表中.新表的数量将反映您的数据的规范化,您选择多少表将取决于数据之间的关系.
Another approach may be to create a number of new tables, each with their own primary key and then copy the data from your existing table into these other tables. The number of new tables would reflect a normalizing of your data and how many you choose would be dependant upon how the data relates to each other.


这篇关于现有表上带有nu唯一字段的SQL主键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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