SQLTeam.com | Weblogs | Forums

SQL trigger to isolate new updates in a table


I am a total noob to SQL, maybye my problem can seem basic.

I have a table that collects data from sensors, and i want to only take the new data to send it on a broker.
So, i made a trigger AFTER UPDATE, but I can't find how to select only the last lines added to the sensors table, and what to do with it (put it in a temporary table ?).

Can you help me please ?

Your problem statement is not very clear. If I understand correctly, data from several sensors are being written into a database table. Then at some point in time, you want to get the latest row that was inserted or updated and do something with it.

Assuming that is correct, you need some way to identify the row that was last updated. One way to do this would be to have a modify_date column in your table and update that with each insertion or update. Then, you can select the row with the highest modify_date value.

What I described is just generalities. Post more details on your problem, the table structure, sample data etc. and someone on the forum would be able to help you.

Is there an audit colum datetime stamp column or a basic datetime column

If you are looking at using a trigger - then you want to use the virtual table 'inserted' which will contain the rows updated/inserted. I also think you want to implement this for both inserts and updates.

I am sorry I was unclear. As I said, I have never done this kind of stuff and don't know what i need to say.
This is correct. Data from several sensors are being written into a database table and, whenever there is an update to the table, I want to get the latest row that was inserted.

Table structure :
I have a TimeStamp column, I can use this ?

There is a TimeStamp column yes

Oui there is timestamp and yoi can use that to find latest data