Click here to Skip to main content
11,707,167 members (56,473 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: SQL Server
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 - 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 that case will there be any insert and update problem?
Posted 23-May-12 5:23am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

This article explains better than I can in a quick answer![^]

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.
losmac at 23-May-12 12:50pm
Very good answer and useful link, my 5!
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 141
1 Sergey Alexandrovich Kryukov 135
2 chainerlt 110
3 Maciej Los 80
4 ppolymorphe 79
0 OriginalGriff 9,178
1 Sergey Alexandrovich Kryukov 8,512
2 CPallini 5,189
3 Maciej Los 4,766
4 Mika Wendelius 3,696

Advertise | Privacy | Mobile
Web03 | 2.8.150819.1 | Last Updated 23 May 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100