Is it possible to have a char primary key on a table? For example ‘WC001’ then will it automatically increment by 1, so the next record for the pk will be ‘WC002’ and so on.
Can anyone provide me example?
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Not directly – but you could have a normal
INT IDENTITYauto-incrementing numerical ID and then defines a computed persisted column (SQL Server 2005 and newer) – something like:Inserting values into this table will cause the
IDcolumn to be1, 2, 3, 4, 5,….. and theCharIDcolumn will automatically beWC001,WC002,WC003and so forth.Since it’s a persisted computed column, the values is always up to date, and you can even put an index (like the primary key) on it.