[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Check Constraint for varchar length in a Password field

Posted on 2010-03-28
8
Medium Priority
?
987 Views
Last Modified: 2013-11-05
I'm having an issue with a field that I want to set a constraint on. I have a 'Password' field that I want to set a constraint of 8 characters or greater on. Using the Sql Server Mgt Studio I choose the check constraint button what is the code that I should use?
0
Comment
Question by:corporateKeenan
  • 4
  • 3
8 Comments
 
LVL 22

Expert Comment

by:Om Prakash
ID: 28939468
create table Table1t
(
Mycolumn varchar(12) check (len(Mycolumn) >= 8)
)

--This will give you error... as the length is 6 chars.
insert into Table1t values ('12abcd')

--Alter statmement to set the constraint.

alter table Table1t add constraint Mycolumn check (len(Mycolumn ) >= 8)
0
 
LVL 57

Expert Comment

by:Raja Jegan R
ID: 28943091
Though above solution would work right for you, request you to do the validation from the front end application since that would be more efficient compared to the check constraint done at the database..

CHECK constraint at database level will throw an exception to your front end application which will break your application if not handled properly..
0
 

Author Comment

by:corporateKeenan
ID: 29093132
Unfortunately the suggestions didn't work. I not sure if you read that I was using the SQL SERVER MANAGEMENT STUDIO's "Add Constraint" button. It would not allow the code of Password check (len(Password) >=8) it kicked back errors.
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 57

Accepted Solution

by:
Raja Jegan R earned 2000 total points
ID: 29098925
try running this ALTER syntax which might help:

ALTER TABLE ur_table
ADD CONSTRAINT password_check CHECK (len(rtrim(password)) >= 8 );
0
 

Author Comment

by:corporateKeenan
ID: 29361910
Still no resolution via the Management Studio. I will be closing this thread, thanks anyways.
0
 
LVL 57

Expert Comment

by:Raja Jegan R
ID: 29460244
>> Still no resolution via the Management Studio.

Have you tried the TSQL command as in my comment# 29098925
And SSMS has some bugs like this and request you to do everything in TSQL to get tasks done..
0
 

Author Comment

by:corporateKeenan
ID: 29461128
I haven't tried the TSQL command yet I had decided to move on to some other tasks that needed to be developed on the database. I will revisit again this weekend because the development team needs the DB by Monday.
0
 
LVL 57

Expert Comment

by:Raja Jegan R
ID: 29461473
Ok.. Try that TSQL approach and let me know your comments..
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
MSSQL DB-maintenance also needs implementation of multiple activities. However, unprecedented errors can hamper the database management. In that case, deploying Stellar SQL Database Toolkit ensures fast and accurate database and backup repair as wel…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Suggested Courses

591 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question