Table with default value not loaded

Asked

Viewed 36 times

-1

I created a table GrupoDesconto, with three fields: Id, Descricao and MargemDesc.

On the table Revenda, created a foreign key (Foreign key) GrupoDescontoId who receives the id of GrupoDesconto and default 1.

When rotating the table Revenda already populated, I observed that the column GrupoDescontoId was null and not with value 1.

What should I do?

  • 3

    cry, if not filled when inserting no option

  • Place DEFAULT in the VALUES list at the position corresponding to the field. In your case: ... VALUES(Group value_discount, DEFAULT)

1 answer

0

If it is possible to remove the column and recreate, you can always do the following:

ALTER TABLE Revenda 
DROP COLUMN GrupoDescontoId

ALTER TABLE Revenda 
ADD         GrupoDescontoId INT 
CONSTRAINT  Revenda_GrupoDescontoId_DF DEFAULT(1) NOT NULL

In allocating the NOT NULL to the column at the same time as defining the DEFAULT CONSTRAINT allows the column to be filled, for all existing records, with the default value, in this case the 1.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.