check and default values

0

I have a store to keep records, I would like to know how I can do it to have values check but if I do not enter any value have a default

I tried to put them out of the store by doing alter table but I get an error:

clasula defualt interfiere con clausula check.
create table dulces
(
id int not null, 
nombre varchar(20),
tipo varchar(15),
proveedor varchar(20),
fechacaducidad datetime not null,
);

alter table dulces add constraint ck_tipo check(tipo='a' or tipo='b' or tipo='c' or tipo='d')

alter table dulces add constraint df_tipo default 'n/a'

create procedure spInsertDulces(@id , @nombre varchar(20),@tipo varchar(15),@proveedor varchar(20),@fechacaducidad datetime)
as begin
if NOT EXISTS (select* from dulces where id=@id)
begin 
insert to dulces(id , nombre ,tipo ,@proveedor ,fechacaducidad)
values(@id , @nombre ,@tipo ,@proveedor ,getdate())
end
    
asked by Raul.Sen 03.07.2017 в 17:13
source

1 answer

0

You have a conflict between the default value of the field and the CHECK clauses. In the latter you should add the default value "n / a" as valid, for example:

alter table dulces add constraint ck_tipo check(tipo='a' or tipo='b' or tipo='c' or tipo='d' or tipo='n/a')
alter table dulces add constraint df_tipo default 'n/a' for tipo
    
answered by 03.07.2017 / 23:44
source