mysql get last modify date for data - mysql

I wanna get last date when i make change in tables something like update add remove so not last modify date that table structure have been changed!
is there any way to catch this?

There is a way. But involves either writing a trigger to insert information into a "log table", or adding a last_update_time column to your table and keeping it up to date always. There is no automatic way of doing it.

Related

Inserting a 'day' column in Access

I'm working in Access and currently have a column with a time stamp in the format DD/MM/YYYY hh:mm. I'm trying to insert a column next to it that only contains the relevent day in number format without the rest of the timestamp. I'm sure this is painfully simple but for some reason I can't figure it out.
Many thanks,
Matt
In a query, add the expression:
Day([YourTimestampFieldName])
In a form with a textbox, use this ControlSource for the textbox:
=Day([YourTimestampFieldName])
If relevent day in number format means something else than the day, please specify.
You have multiple options.
You can design to column to be a specific format in the table design view. This will enforce date formats for you. Its been a minute for me, but I believe it even works as you try to insert into that column.
You can use the FORMAT function on inserts, as getting data from another column/data type is what youre doing. its actual specific use is of:
FORMAT(yourColumn, "MM-DD-YYYY")
If you need more specifics, you can google the function.
You can set up a macro that will function like a trigger in normal RDMS's. This i envision will UpSert the value to the new column based on INSERT/UPDATE logic.
Let me know if you think this requires more assistance. I think this should be more than enough to get you started.

Deleting/Copying the data from Database with specific condition in mySQL

I am looking for an Idea to handle data in DB directly.
Here is my use case
I have table “EVENT_REGISTERED” with column (ID, Event_name,Event_DateTime)
I want to display the EVENT_REGISTERED in the fronted end whose date and time is not passed. i.e. I want to display only Upcoming event not Historical events.
Of course this can be handle with JS code before displaying.
But What I want is there should be some sort of a trigger which will delete the Instance form the “EVENT_ REGISTERED” table and copy it to another Table “HISTORICAL_EVENT”
I cannot Create an MY SQL EVENT to do this as it like batch job and I cannot run this every 5 mins as there can be more than 10000 rows in there.
I see Trigger option as well, I am not sure how to use this as it says that it will be activated after the specific action is executed. Here the specific action is CURRENT_DATETIME == EVENT_DATETIME.
Can anybody give me a direction or any sort of alternative way to achieve this?
**I am not an Expert of MySQL*
Thank you
Regards
Prat
Don't start moving rows between tables. Simply run a query:
select er.*
from event_registered
where er.event_datetime > now();
With an index on (event_datetime), performance should be fine.

Get the date when the row was inserted MySQL

Is there any way to get a datetime when the row was created? Is it stored anywhere? I just forgot to add a column which tells when the row was inserted, and lots of rows have been inserted and I don't know when they were inserted... Thanks.
Unfortunately there's no way to achieve that. MySQL doesn't store a timestamp of row creation, that's why you always have to create a column to do that, along with ON UPDATE clause which will update the column every time the row is updated
Nope. You need a column to record that, it's not stored in the system otherwise.
There isn't a way to get timestamp when the row was created unless you add a field that is populated with system time or has a default value.

MySQL: find out what date a row was added to a table?

I added a new column to a table called price_request_date because I now need to track the date each one was made. I made it so new ones enter the current date when they insert a new row. I was just wondering if there was any way to fill in the previous rows with the dates they were entered? I don't know if MySQL keeps track of that sort of thing or not, but worth an ask. Thanks!
There is not. There is no way to automatically backdate a timestamp field with the original creation date if it weren't already set at creation time.
Frustrating - I know.
nope. it is good to always include LastChgID and LastChgDate on tables like this, do that next time from the get go...

Detect time of last change on a Microsoft Access database table

Does anyone know of a way to detect when the last time a Microsoft Access table has been changed (inserted into or updated)? We used OLEDB via ADO COM to communicate with an access database programmatically and were looking for a way of detecting changes to specific tables. We don't need to know what those changes are, just that changes were made.
The only way to detect if data in the table has changed is to perform a query against the table.
You must add a column of type DATETIME to the table e.g. named LastUpdatedDate that indicates the last updated date/time of each row. Make it NOT NULL so that you will have to write an updated DATETIME value to that column for each INSERT or UPDATE. Also, set the column to have a default of DATE() for the current date stamp or NOW() for the current date/time stamp. Then add a Validation Rule or CHECK constraint e.g. CHECK (LastUpdatedDate = NOW()) to ensure the column is actually updated on each UPDATE and INSERT.
Finally, run a MAX(LastUpdatedDate) query and you will get what you need.
There isn't a way without "manually" writing to a column each time you access the table.
As others have indicated there is no way to track changes without coding it yourself.
There's a simple example at
ACC2000: How to Create an Audit Trail of Record Changes in a Form
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q197592
Audit Trail - Log changes at the record level at:
http://allenbrowne.com/AppAudit.html
The article addresses edits, inserts, and deletes for a form and subform.
Modules: Maintain a history of changes
http://www.mvps.org/access/modules/mdl0021.htm
The History Table routine is designed to write history records that track the changes made to fields in one or more tables.
You will need to implement a timestamp column in your table, and update the value during your data changes.