大小超过900字节的SQL Server主键问题 [英] sql server primary key with size over 900 bytes problem

查看:581
本文介绍了大小超过900字节的SQL Server主键问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想分配一个列,因为主键大小超过900个字节,并且我得到的列大小超过900个字节错误.我不得不减小大小以使其成为主键.问题-
1.是否有更好的选择将键分配给超过900字节的列大小
2.假设我将列的大小减小到小于900字节并将其分配给主键,但是我的其他列的总大小通常超过900字节,因为要保存许多长数据,在这种情况下将有任何插入和更新问题?

i wanted to assign a column as primary key size is over 900 bytes and i got column size is over 900 bytes error.i had to decrease size to make it a primary key.question -
1.is there any better alternative to assign key to a column size over 900 bytes
2.suppose i decrease size of the column less than 900 bytes and assigned it primary key.but my other columns total sizes are more than 900 bytes as usual as there are many long data to be saved.in that case will there be any insert and update problem?

推荐答案

本文比快速解答中的解释要好!
http://blogs.msdn.com/b/bartd/archive/2011/01/06/optionsforindexedlookupsoflongvalues.aspx [ ^ ]

基本上,您需要重新考虑关键设计.您是否要使用包含长字符串的字段或字符串字段的组合来创建主键?

根据该文章的建议,我将继续使用IDENTITY规范创建一个主键字段,这将立即解决此问题.然后,您可以考虑使用某些唯一约束或其他索引来提供数据库完整性和性能.
This article explains better than I can in a quick answer!

http://blogs.msdn.com/b/bartd/archive/2011/01/06/optionsforindexedlookupsoflongvalues.aspx[^]

Basically, you need to reconsider your key design. Are you trying to create a primary key using fields that have long strings in, or combination of string fields?

Out of the suggestions in that article, I''d go with creating a primary key field using the IDENTITY specification which will solve this issue immediately. Then, you could consider some unique constrainsts or other indexes to provide database integrity and performance.


同意Dylan Morley的观点,尽可能使用代理键(始终)并将自然键定义为唯一.

与迪伦的答案唯一的不同是,我个人更喜欢使用 uniqueidentifier [ ^ ]而不是IDENTITY.例如,原因之一是uniqueidentifier可以用于需要复制的环境中.总体而言,它更加灵活.
Agree with Dylan Morley, use surrogate keys whenever possible (=always) and define the natural keys as unique.

The only difference to Dylan''s answer is that I would personally prefer a uniqueidentifier[^] instead of IDENTITY. One reason for example is that uniqueidentifier can be used in environments where you need replication. In overall it''s more flexible.


这篇关于大小超过900字节的SQL Server主键问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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