Jump to content

Sql query help..


Sarvapindi

Recommended Posts

Sql experts randi va..oka qn

i have a table ..

Table A...   With 1000 records with columns below

id.   Name

this table will be updated everyday...so some records will be deleted or some new records will be inserted. I want to find what are the records thats r inserted and records that r deleted everyday...and load those into another table...

how to do

Link to comment
Share on other sites

1 minute ago, Sarvapindi said:

Sql experts randi va..oka qn

i have a table ..

Table A...   With 1000 records with columns below

id.   Name

this table will be updated everyday...so some records will be deleted or some new records will be inserted. I want to find what are the records thats r inserted and records that r deleted everyday...and load those into another table...

how to do

daily snapshot teesi data ni inko table lo pettu (Table B).. danito Table A data ni compare chesi neeku kavalsina table lo load cheyyi.

 

Once load done delete records from Table B and reload it with Existing Table A data for next iteration.

  • Haha 2
Link to comment
Share on other sites

Just now, AndhraneedSCS said:

Write a trigger and convert the inserts and deletes into an insert into the different table. 

 

 

Hmm..actually that table gets loaded from a file...

Link to comment
Share on other sites

1 minute ago, BetterThief said:

daily snapshot teesi data ni inko table lo pettu (Table B).. danito Table A data ni compare chesi neeku kavalsina table lo load cheyyi.

 

Once load done delete records from Table B and reload it with Existing Table A data for next iteration.

gud ba..sql steps cheppu jara

Link to comment
Share on other sites

It doesn't matter how the table gets populated. 

 

Trigger will fire up on insert/delete/update on your table,. All your trigger will do is populate this data into another table (call it dummy) and identify if it is an insert/update/delete and continue the operation on the main table.

 

Your dummy table . will have all the information you may need and you just have to query it to see what inserts/updates/deletes ran on that table.

 

if this is a mission-critical table that has 100s of transactions per second through out the day, this approach can cause performance bottleneck. Otherwise, it will work just fine.

 

 

Link to comment
Share on other sites

CREATE TRIGGER name_table
ON name
AFTER UPDATE,INSERT
AS 
BEGIN
    INSERT INTO name_change_history(
        id,
        old_name,
        new_name,
        date_of_change
        )
    SELECT 
        i.id,
        d.name,
        i.name,
        GETDATE()
    FROM inserted i
    LEFT JOIN deleted d
        ON i.id = d.id
    WHERE i.name != ISNULL(d.name, -1)
END;

 

Link to comment
Share on other sites

1 hour ago, Sarvapindi said:

Sql experts randi va..oka qn

i have a table ..

Table A...   With 1000 records with columns below

id.   Name

this table will be updated everyday...so some records will be deleted or some new records will be inserted. I want to find what are the records thats r inserted and records that r deleted everyday...and load those into another table...

how to do

trigger

Link to comment
Share on other sites

2 hours ago, Spartan said:

CREATE TRIGGER name_table
ON name
AFTER UPDATE,INSERT
AS 
BEGIN
    INSERT INTO name_change_history(
        id,
        old_name,
        new_name,
        date_of_change
        )
    SELECT 
        i.id,
        d.name,
        i.name,
        GETDATE()
    FROM inserted i
    LEFT JOIN deleted d
        ON i.id = d.id
    WHERE i.name != ISNULL(d.name, -1)
END;

 

Super bro nuvvu

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...