Click here to Skip to main content
15,904,024 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi
I have "login" field in my Users table. login is of nvarchar(max) datatype.
I would like to set this field as Primary. but db is not allowing to set primary for nvarchar. How can I set Primary key for nvarchar fields?


Thanks and Regards
Posted
Comments
jim lahey 13-Apr-11 6:03am    
why do you want nvarchar as a primary?

You cant mate.
(MAX) length wont be accepted as PK.

Use int instead and make your nvarchar(max) as index.
Using nvarchar as PK will make your searching really slow.

But if you still want to use nvarchar, declare the length. Something like this..
CREATE TABLE Login(
P_Id nvarchar(10) NOT NULL PRIMARY KEY,
password nvarchar(100) NOT NULL
)
 
Share this answer
 
v2
Why would you need nvarchar(MAX) for "login"? That means you expect 2^31-1 bytes for the login.
Change datatype for "login" column to nvarchar(20) or something more realistic.
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900