Creation date of a row

  • Hi,

    The problem is, the database is growing everyday and now the option right now is to archive all records before Jan 1st 2009 into a new DB. But in none of the tables the creation/modified dates are stored. How can i get these record creation and modified dates?

    Thanks in advance 🙂

  • without a field holding this information, you can't get it sorry.

  • Thanks for the fast reply

    always thought there would be some built-in timestamps for records inserted. is there any workaround for this?

  • not really.

    you could restore a backup from prior to 1st Jan 2009 (if you have one) to another db and use this as the basis for comparisons to find out earlier records.

  • You could add a datetime column with a default of getdate for future use. That would show you when it was added, but not when it was modified. You'd need to modify your applications for that.

  • Yes i could restore a backup with DB prior to Jan 1st 2009, but i would need another DB containing only the records which were added after Jan 1st 2009. The other records prior to that, i need to put them in another archive DB. Is there any way to separate them?

  • prady_1988 (4/1/2011)


    Yes i could restore a backup with DB prior to Jan 1st 2009, but i would need another DB containing only the records which were added after Jan 1st 2009. The other records prior to that, i need to put them in another archive DB. Is there any way to separate them?

    Surely if you have a set of all rows from before that date (the old backup) and the set of all rows, it's a trivial query to get the one that are only in the one table. Exists, In or Except will do the job.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • GilaMonster (4/1/2011)


    prady_1988 (4/1/2011)


    Yes i could restore a backup with DB prior to Jan 1st 2009, but i would need another DB containing only the records which were added after Jan 1st 2009. The other records prior to that, i need to put them in another archive DB. Is there any way to separate them?

    Surely if you have a set of all rows from before that date (the old backup) and the set of all rows, it's a trivial query to get the one that are only in the one table. Exists, In or Except will do the job.

    So do i need to check if each and every primary key exists and then insert it?

  • If by 'each and every' you mean a cursor or a row-by-row comparison, no.

    Look up EXISTS (and IN) and it should become clear how they work. If you need further help, post the table definition.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • to help you visualize, here's a prototype to review and get your head around it.

    assume you added a CreatedDate column today to a specific table.

    you restored a backup as suggested to a database named 'History'

    now you can compare old data vs new data.

    you could update with an IN or EXISTS as suggested:

    UPDATE PRODUCTION.DBO.INVOICES

    SET CREATEDDATE = '01/01/2009'

    WHERE INVOICEID IN

    (

    --this may select a million records...

    SELECT INVOICEID

    FROM HISTORY.DBO.INVOICES

    )

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Viewing 10 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic. Login to reply