How can one set the column value length to a minimum and/or exact length using MS SQL Management Studio?
Share
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.
For character datatypes (char/nchar/varchar/nvarchar), you set the length:

Remember that for
charandnchar, you’ll ALWAYS be allocated the x bytes space, and your string will be padded.ncharalways has 2 x allocated, but the string length will be as you specify.For string-length minimums, that really should be left to the application.
SQL Server does allow you to put a constraint on a column.
In this example, the constraint is that the column value be >= 10.
Simply write a TSQL expression in the Expression field.
LEN(myColumn) = 20– the value being inserted/updated in the column is length of 20.LEN(RTRIM(LRTIM(myColumn))) = 20– the value being inserted/updated in the column is length of 20, with all leading/trailing whitespace removed.