Limit sql server field

-1

I have the following table with the password field that has to be limited to 6 neither more nor less, I tried with the modifier check but only assign it numbers or letters, there is some way to limit it to 6 but they can be any of the 2 things?

create table Empleado
(ci int not null,
contraseña varchar(6) not null,
nombreCompleto varchar(20) not null,
primary key(ci),
logica bit default(0))
go
    
asked by bruno birriel 05.09.2018 в 22:33
source

1 answer

2

Ok, ignoring the fact that having a password with an exact fixed length is bad practice, that it is only 6 characters makes it even worse and that it is also saved in plain text ... this can be easily done:

CREATE TABLE Empleado ( ci int NOT NULL, 
                        contraseña varchar(6) NOT NULL CHECK(LEN(contraseña) = 6), 
                        nombreCompleto varchar(20) NOT NULL, 
                        PRIMARY KEY(ci), 
                        logica bit DEFAULT(0) 
                      )
;
    
answered by 05.09.2018 в 22:50