Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run SQL on only new records?

Status
Not open for further replies.

pmoran10

Technical User
Joined
Mar 5, 2010
Messages
1
I dont have much SQL experience but i need to insert a trigger into a table but there is about 10 million records and it seems to run through all the old records when i only want it to insert the trigger and run it on any new records not the 10 million old ones, it was taking hours

-- Trigger: f_tscrec1_trigg on playercolumns

-- DROP TRIGGER f_tscrec1_trigg ON playercolumns;

CREATE TRIGGER f_tscrec1_trigg
BEFORE INSERT
ON playercolumns
FOR EACH ROW
EXECUTE PROCEDURE f_tscrec1('tscrec');

So i just want it to insert the trigger now and everytime it inserts a new record run the trigger, its fine on smaller databases but on bigger ones its a disaster. Any ideas, as i said im a newbie to SQL? Im just inserting this via PGadmin in the SQL query tool

This is a postgreSQL database btw but i presume the SQL query is universal?
 
Better to post in a postgreSQL forum. That syntax is completely different from SQL Server syntax.

But I am going to guess your main problem is that you are executing that procedure multiple times. If postgre is anything like SQL Server, you don't want to "execute this for each row," you want to "execute this against this set of rows." One operation -- not multiple.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top