Welcome Guest, Not a member yet? Register   Sign In
"updated_at" field filled during an insert operation
#1

the updated_at field filled during an insert operation, not only created_at field. Even though I only intend to insert into the database. is it normal?

thanks.
Reply
#2

Yes anytime you update a database record the updated_at field will ne updated.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

Thank you for your quick response...

So, it's normal for both the 'created_at' and 'updated_at' fields to be filled when we INSERT data into the database (not update operation).

PS: i'm using SQLite3
Reply
#4

Created_at is only created when the record is created.

updated_at is updated every time the record is changed with new data.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#5

(07-12-2024, 10:06 PM)InsiteFX Wrote: updated_at is updated every time the record is changed with new data.

Thanks @InsiteFX , but I don't understand the second sentence. Will 'created_at' be updated even though it is the first time the record is inserted?
Reply
#6

The structure to be used is as follows:
type => DATETIME
default => null
attributes => on update CURRENT_TIMESTAMP
If plan A fails, relax... the alphabet is 26 letters
Reply
#7

(07-13-2024, 07:26 PM)wdeda Wrote: The structure to be used is as follows:
type => DATETIME
default => null
attributes => on update CURRENT_TIMESTAMP

my SQLite IDE does not support the DATETIME data type; it only allows text or integer types.
Reply
#8

created_at is only set once when the record is created, it will never be set again unless you change it.

updated_at is changed every time you insert or update the record.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#9

My apologies, I didn't actually read your remark that you use SQLite3. I agree with @InsiteFX, but what you reported is possible to happen in MySql if 'updated_at' is not set properly.
If plan A fails, relax... the alphabet is 26 letters
Reply
#10

(This post was last modified: 07-14-2024, 08:36 AM by Renta Ardhana.)

(07-13-2024, 10:08 PM)InsiteFX Wrote: created_at is only set once when the record is created, it will never be set again unless you change it.

updated_at is changed every time you insert or update the record.

Thank you, the answer that really helps me understand why the updated_at field contains data even though I only inserted new data once.

(07-14-2024, 04:11 AM)wdeda Wrote: My apologies, I didn't actually read your remark that you use SQLite3. I agree with @InsiteFX, but what you reported is possible to happen in MySql if 'updated_at' is not set properly.

I also forgot I was using an SQLite db[Image: smile.png]
Reply




Theme © iAndrew 2016 - Forum software by © MyBB