Fetching rows changed or added last day without time field? - mysql

I want query a table to find the changed rows last day. But there is no explicit time filed in column name. Is there any way I can access these data?

Without a field indicating when a record was changed there is no way to determine when a record was changed, therefore it is unfortunately impossible for you to query the records changed yesterday.

Related

Is there a way to know the number of records added into the SQL database after a particular date and time

The table doesn't have any date time column. I want to if there is any inbuilt keyword which can does that.
I want to know all commits done after a particular date.
If flashback is enabled on the database you can get records on the table in an around a particular date range in Oracle.(It purely depends on if its enabled and for how long the flashback needs to be kept)
You can query to see the data in the table as of 3 days back as follows
select *
from table as of timestamp sysdate-3

Sorting by time not working truly in MySql

I think title is clear what is my problem. I am working with MySql I just wanted to know what was the first registration on my website and when I sorted the table according to timestamp, the id of people who registered on the website were not true. The Image bellow will show what do I mean:
and this is the code what phpMyAdmin created:
SELECT *
FROM `table`
ORDER BY `table`.`timestamp` ASC
LIMIT 0 , 30
whats wrong with my table time? and why id is not ordered same as timestamps
If we assume that id is an auto-increment field, then this is almost certainly due to the fact that timestamp column is not assigned at the same physical time the id column is assigned. For example, if you have a multi-page registration from a website application, the initial object may be inserted into the database to contain the initial data fields gathered on the first page. But perhaps the timestamp is only set after the final page of registration is complete. So depending on the time the user takes to complete registration, the timestamp can be out-of-sync with the id order.
There are multiple ways to work around this. One way is to assign timestamp when the record is first inserted into the database, or you could use a DB insert trigger to populate the timestamp field instead.
There is also the possibility that timestamp represents the date and time the user last modified their profile (or otherwise caused modification of the database record). In this case, the timestamp could be changing to a "future" value while the id stays constant.

Getting Rows Inserted After some date/time

I need to get all the entries that were added 'today', ie 24 hours prior to the point of execution. It is simple enough to do so with date column, which I don't have. Is it at all possible to find these rows without such column?
Thanks
No, you can't do it. If you don't have a date stamp on the row, then there's no way of knowing when it was inserted.

Extract results updated in last 2 hours

I am trying to write a query to extract records updated in the last 2 hours in SQL Server 2008.
Could anyone help me write this?
select * from table where table.date1>=dateadd(hh,-2,getdate())
dateadd() function lets you subtract hours from getdate() letting you choose records updated past 2 hours
First, you have to design the table so you have a field where the time of the last change will be stored
Then, whenever you update a row, update the value in the 'last update' field. After that, you can use a script such as suggested by Vijaykumar
The downside of this method is that when a single record was changed more than once in the specified time period, you will be notified only about the time of the last update.
Another solution for tracking the updates is to read the database online transaction log file, but you'll need a third party tool for that

Timestamp is generated for next record, as opposed to current record

I have a slight issue with MS-Access, which is as follows.
I have a table with a Timestamp column (the format of the field is Date/Time, the default value is Now()). The issue is that whenever I create a new record, the timestamp is set for the next record I am going to create, as opposed to the record I am creating.
This means that I create record 50, and the Timestamp is set for record 51. If I come back a week later, and create record 51, the Timestamp for record 51 will be a week out, and the timestamp will be set for record 52, which I will be creating at some point in the future.
You can re-create the problem by firing up MS-Access, creating a new table with a couple of fields, one of which is Date/Time and setting the Default Value of this field to Now().
Is this by design, or am I doing something dumb? If it is by design, how can I implement the type of Timestamp that I want (one where the Date/Time is set as the record is created) in MS-Access? If I am doing something dumb, what exactly am I doing?
Edit: Below is a screenshot of a newly created Access table:
I add some text to record one, the Timestamp gets set for record two:
I allow some time to pass, put some data into record two, and the timestamp doesn't change, and now record three has a timestamp:
If I close and open the table, the Timestamp for the (New) record gets updated to whenever I opened the table:
I allow some time to pass, update the record and the Timestamp stays at the time I opened the table:
As is already revealed in the comments, this problem comes from editing in the table with Now() set as the Default for your TimeStamp field.
I suggest you create a form instead of editing in the table. If you want it to look similar just use a datasheet form. Then on the Form's BeforeUpdate event put code in like this:
Me!TimeStamp = Now()
As a side note, I wouldn't use TimeStamp as a field name. Some RDBMS such as SQL Server have a data type called TimeStamp. It's best to avoid using field names that are data types or reserved words. Moving an Access database to SQL Server is extremely common and you could have problems when you try to do it.
Instead, I would create two fields. One called DateTimeEntered and another called DateTimeModified. I consider these two fields to be necessary in pretty much every table I make. If you ever want to do any kind of synchronization of records you'll wish you had at least a DateTimeModified field.