How to delete only records from a field of my table in SQL

Asked

Viewed 793 times

-2

Good morning, I would need to delete only those registered from a field of my table. In the case I have the product table and in it has the field dtsanitation and in this field had records. I would need to delete only the records from this field and keep the table and other information intact. Could anyone help me ?

3 answers

2

update produto set dt_saneamento = null;

Update the table by setting the field to null.

2

table = Name of your table

column = Column you want to clean

UPDATE tabela SET coluna = NULL

In your case it would look like this

UPDATE produto SET dtsaneamento = NULL
  • One thing I forgot to mention, I need to keep the 2019-01-01 date on and the previous ones will be null, as would the code ?

  • 1

    In case you add a clause in your UPDATE, it would look like this UPDATE product SET dtsanitation = NULL WHERE data < 2019-01-01

1


You can do it this way

UPDATE produto SET dtsaneamento = null;

Edited

To delete only records prior to date just do so

UPDATE produto SET dtsaneamento = null where campo_data < "2019-01-01";

If your field is date and time do so

UPDATE produto SET dtsaneamento = null where cast(campo_data as date) < "2019-01-01";
  • One thing I forgot to mention, I need to keep the 2019-01-01 date on and the previous ones will be null, as would the code ?

  • 1

    @Matheusribeiro Check the edition of my reply.

Browser other questions tagged

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