The date of a sale changes when the record of the sale is updated

Asked

Viewed 47 times

-1

The column data_venda TIMESTAMP(0) of my table venda returns the current time of sale on my sales registration form.

Only on an update form where I update the sale schedule changes, and I didn’t want that kind of thing, because if a sale was made last week it should stick to the sale schedule last week. How I get it?

  • 2

    only do not update this field in the table when updating the sale, or be sure to pass the same value that already exists

  • I did not put this field to update, but updated the same way.

  • good without seeing the code becomes difficult, but the basic solution is either not update or take the current value before updating

2 answers

-2

Ever tried to change the assignment of the TIMESTAMP field when creating the table? Could you test by putting the CURRENT_TIMESTAMP or the DEFAULT NOW()

Follow an example:

CREATE TABLE TBL_VENDA (
data_venda1 DATETIME ON UPDATE CURRENT_TIMESTAMP,
data_venda1 DEFAULT NOW()
)
  • Just signaling, that this change might be useful if it is possible to make this change in the table itself. I hope I helped Dev Snake

-2


Prevents mysql from changing the field data_venda when there is a UPDATE

CREATE TABLE venda (
   data_venda TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
  • https://dev.mysql.com/doc/refman/8.0/en/timestamp-initialization.html

Browser other questions tagged

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