I need to provide a date for an app to check for updates.
For this I need to get the last date some of my tables in my database were modified.
I was checking for the last updated record in the table like this:
MyTable.find(:first, :order => "updated_at DESC")
but then I notice, that if I delete a record, I will get the previous updated record, which will be "obsolete", I need to get the date where the last record was deleted or modified.
Is there a way to obtain this without having some sort of global variable keeping up all of the changes that are being made?
Thanks
Maybe you need something like the Audited gem.
Related
Problem: I have accidentally overwrite a view in SnowFlake using CREATE OR REPLACE VIEW.
Question: Is there anyway to retrieve the old view i.e. the SQL code?
You can use QUERY_HISTORY to find the previous DDL used to create the query.
You can filter results using QUERY_TYPE which will help to you to find quickly the right query type.
If you can't find it in the query history tab using QUERY_TYPE > CREATE, you can search for it over the previous 365 days in the query history. This previous post has the SQL to run:
View DDL history of CREATE VIEW statement in Snowflake
Note that this is a big query if your account has run lots of queries over the last year. You can modify it to reduce the scan if necessary if you know more information, such as the month of creation.
If you want a totally informal and lightweight way to version your objects, I wrote one for my internal use that I decided to share. It's a table and stored procedure. Call the stored procedure with the object type and three-part name, and it adds a version row to the table. If it finds a pervious version, it marks the old one obsolete as of the current_timestamp and increments the number of the new version by 1.
https://github.com/GregPavlik/SimpleVersioning/blob/main/install.sql
Is there a way to perform a query for records of a table with an extra clause to exclude a user that the data has been last updated by without adding a new column? For example, I want to query for records that have not been last touched by my current user. Does Snowflake store and allow use of something like this behind the scenes?
Thanks in advance!
I am working in SQL Server 2008 R2 and have a production table that I need to replicate exactly in another location to work on. I will first run a job to move everything over (once off) and then run a daily job to update the updates/inserts daily.
The daily job will look at the production table and find any new values that need to be inserted (based on a created date) and also find any existing values that need to be updated (based on a modified date). Any new values are inserts and any modified values are updates.
The job pulls these rows from the production table and applies them to the copy table located elsewhere. I am running into trouble with timestamp columns. The production table has a timestamp column and I don't know how I should handle this when updating the copy table (also created as a timestamp column).
I get an error if I set the production.timestamp_col = copytable.timestamp_col (Cannot update a timestamp column).
Should I leave it out (in which case I don't have an exact copy of the table), convert the column in the copy table & the value in the select from the production table to something else (not sure what), put my own value in (again, won't have an exact copy of the table) or drop/truncate and recreate each time (inefficient due to data volumes)?
What would the best approach be in a situation like this?
Thanks
You can convert the destination timestamp column to varbinary(8) and then insert the values. This will help you create an exact copy but it will break the timestamp functionality. Do this if you need to have a copy only. The actual purpose of timestamp column is to track changes to a row through versioning.
In SQL a timestamp column is system generated, you cannot update it or set it on insert. SQL does this all for you.
https://technet.microsoft.com/en-us/library/ms182776(v=sql.110).aspx
You may be able to pull something off with replication/mirroring to get a 100% exact copy, but it may not be worth it depending on your needs.
i am using oracle 11. I need to find when specific column was created. I know we can find out last DDL change date but first i created the column
and after some days created index on one of the column of same table . So now, I need to find when that specific column was created .
Is there a way ?
This depends on your audit settings if the object was being audited you may find it in audit trail. I'd suggest reading
http://docs.oracle.com/cd/B28359_01/server.111/b28337/tdpsg_auditing.htm
Or you can use LogMiner to check redo logs if you DB was running in ARCHIVELOG mode. But I have never used this so I'm not sure about all the requirements there.
Is there a way in MS access 2007 to create a conditional formatting rule that will highlight any field that has been updated in the past 7 days?
Currently I have a rule that highlights any information that is added in the previous week by field value is between Now()-7 and Now(). I'd like to open up the option to modifying old entries that week and have those highlighting as well.
Thanks.
EDIT:
Essentially the database dates back from approximately 6 months. It tracks progress on projects and employees enter task details in a subform of the project.
Date Employee Task
3/14/2012 David Talked to Remou *about ms-access*
8/1/2012 John Solved world hunger
** denotes updated information, and although the task happened on 3/14, I would like to display the changes with conditional formatting. Currently the only thing that would highlight is the 8/1 event.
By far the easiest way is to add an update date and a username. It won't give you a highlighted text difference, but it will be much easier to implement. As an aside, I always add a created timestamp, created user, updated timestamp and updated user to any user maintained tables. It saves so much trouble, because Access does not automatically add this information.