About deleting old files from a folder

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Zerin
    New Member
    • Dec 2006
    • 56

    #1

    About deleting old files from a folder

    Hi guys,

    I started "autopurgin g" discussion many days ago.As I couldn't do it,so I decided to change my database into SQL Server.And so posted this problem here.

    Plain and simple ------ I have a database named TANI and it has a table named "TANI" as well.

    Table TANI has 3 fields only ------
    1. CSV FILES that holds a link to some csv files from a folder
    2. IMAGE FILES that holds a link to some image files from a folder
    3. DATE that records the time of data arrival in the database.

    Now, I just want to delete files ( both csv and image files ) from the folder INSPECTION that are 1 month old by using SQL Server triggers.

    Can anyone help me this time?

    Zerin
  • iburyak
    Recognized Expert Top Contributor
    • Nov 2006
    • 1016

    #2
    Try this. Just test it first.

    [PHP]
    CREATE TRIGGER tIUD_machine ON machine
    FOR INSERT, UPDATE,DELETE
    AS
    BEGIN
    DELETE FROM INSPECTION
    FROM INSPECTION I
    JOIN TANI T ON I.[CSV FILES] = T.[CSV FILES]
    AND I.[IMAGE FILES] = T.[IMAGE FILES]
    WHERE DATE < dateadd(m,-1,getdate())

    END [/PHP]

    Comment

    • Zerin
      New Member
      • Dec 2006
      • 56

      #3
      Originally posted by iburyak
      Try this. Just test it first.

      [PHP]
      CREATE TRIGGER tIUD_machine ON machine
      FOR INSERT, UPDATE,DELETE
      AS
      BEGIN
      DELETE FROM INSPECTION
      FROM INSPECTION I
      JOIN TANI T ON I.[CSV FILES] = T.[CSV FILES]
      AND I.[IMAGE FILES] = T.[IMAGE FILES]
      WHERE DATE < dateadd(m,-1,getdate())

      END [/PHP]

      Dear iburyak ,

      Thanks for the reply.Testing now.And 'll let u know.

      Zerin

      Comment

      • Zerin
        New Member
        • Dec 2006
        • 56

        #4
        Originally posted by iburyak
        Try this. Just test it first.

        [PHP]
        CREATE TRIGGER tIUD_machine ON machine
        FOR INSERT, UPDATE,DELETE
        AS
        BEGIN
        DELETE FROM INSPECTION
        FROM INSPECTION I
        JOIN TANI T ON I.[CSV FILES] = T.[CSV FILES]
        AND I.[IMAGE FILES] = T.[IMAGE FILES]
        WHERE DATE < dateadd(m,-1,getdate())

        END [/PHP]

        Dear iburyak ,

        I tried the trigger and it gives the following error message:

        Object 'machine' does not exist or is invalid for this operation.

        Actually,I'm not expert in SQL Server.So,I can't understand what to do.MSDN search also don't have any fruitful reply.Please help !

        Zerin

        Comment

        • iburyak
          Recognized Expert Top Contributor
          • Nov 2006
          • 1016

          #5
          Sorry, I just wrote table name that I have in my database you had to replace it with your test table name.

          You have to change this line.


          [PHP]CREATE TRIGGER tIUD_table_name ON table_name_here[/PHP]


          tIUD_table_name - trigger name

          table_name_here - should be a table name you creating trigger over.

          Good Luck.

          Comment

          • Zerin
            New Member
            • Dec 2006
            • 56

            #6
            Oh !

            What a foolish buddy am I ! I should'v noticed that. Thank u iburyak. Think it'll work now. Many many thanks frnd.

            Zerin

            Comment

            • Zerin
              New Member
              • Dec 2006
              • 56

              #7
              Dear iburyak ,

              It worked with a few change and I could do it by VB 2005 also.Ah! Relax.......... ...........

              Comment

              Working...