3
I wonder if it is possible, when one is made INSERT
in a given table, automatically update the value of another column of the TIMESTAMP type called date with the current date and time, similar to the function NOW()
mysql?
3
I wonder if it is possible, when one is made INSERT
in a given table, automatically update the value of another column of the TIMESTAMP type called date with the current date and time, similar to the function NOW()
mysql?
4
galera got with the simple sql command below. thanks to all
ALTER TABLE `grade_edt` CHANGE `data_ultima_mod`
`data_ultima_mod` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP;
It’s an unusual alternative. The most common is to leave these settings in charge of the application, but, it works.
@Fellipesoares because unusual? It is so relevant to be in the domain of the application the last change of the record?
@gmsantos, if there are any changes to the database hardware, DBMS version change, or even the DBMS exchange, you may need to reshape the table structure, when if the responsibility was of the application, you would not have this concern. It is more a matter of thinking in the development cycle. Perhaps "usual" is not the right word to express.
Changing hardware or Mysql version will not influence the table’s Constraint. Only concern is if the system is going to suffer a change of Sgdb or need to run in several banks. I’m writing an answer to explain this further. But if sgbd never changes from mysql, I find the use of Constraint even better than managing it in the application
I get it. Since the question was not about a specific scenario, an answer taking into account a possible exchange of DBMS may be the most ideal, since this is usually a frequent doubt. I have also had problems with application server in UTC other than database server, for example.
Browser other questions tagged mysql timestamp
You are not signed in. Login or sign up in order to post.
can normally use the function
NOW()
Mysql in your PHP statement. If you are usingbind_param
, just don’t pass the parameter$data
at INSERT, leaving DBMS with this responsibility.– Fellipe Soares
Enter the code that is having problems.
– rray
You don’t understand the OP problem...
– Bruno Augusto
Columns type
TIMESTAMP
(and notDATETIME
) do not do this automatically?– bfavaretto
@bfavaretto, depends on the Mysql version and how Mysql was installed. If it is a current version, an installation is used standard, you’re right.
– Fellipe Soares