June 12, 2005 at 3:48 am
Hi all,
I have a table without auto generated ID or time stamp.
I want to retrieve all the rows that are inserted in the table after a certain row.
How can I do that?
June 12, 2005 at 3:55 am
or i can explain it clearer in the following way:
I have a table without auto-generated ID nor time stamp.
I want to identify the newly inserted rows in a table.
I can't make any modifications to the table.
June 12, 2005 at 6:25 am
Hi Ahmed,
Let me see if I get your question right...?
You want to make a "insert into" statement in a existing table ?
And in this case you want to identify the new rows in the last transaction?
And eather you don't have a uniq key for every record (ID or datetime)?
Why do you not use the function "identity", its easily to use...
Anyways which data do you have in the table... maybe I can do something smart out of it?
aem
June 12, 2005 at 2:29 pm
If your table does not contain something that increases for every row, then you cannot do what you are asking for.
June 12, 2005 at 3:11 pm
If applicable, you could create an insert trigger which would then allow you access to the inserted tables... but this would only apply for a single insert.
IE:
Insert into ... ... ...
--puts X rows in table
(assuming you dont know what X is because it was generated from a select)
it will be in #inserted inside the trigger.. but as others have said, without a datetime or identity column what you want to do isn't possible... i dont think.
June 12, 2005 at 3:15 pm
The concept of row order just does not exist in sql server. Chris is correct! Under the circumstances you describe there is just no way you can reliably determine the order in which the existing rows have been inserted.
If your table has a PK or something that can be guaranteed to be unique then the following may be an option for rows inserted in the future. Create a second table that is linked to the first by the unique attribute and use an auto id or datetime column in the second table to track when it was inserted. You can use a trigger or application code to insert into the second table for each insert into the first table. You'll also have to consider how to handle modifications and deletions to the first table.
June 13, 2005 at 3:00 am
thank you all
June 13, 2005 at 9:14 am
Hello Ahmed,
If you have got the solution, please do post it here...i would love to learn this too....
Thanks.
June 13, 2005 at 9:18 am
It's already been posted in the previous messages... even if it's not crystal clear .
June 13, 2005 at 9:28 am
no I didn't get a solution..
I had to use the trigger method.
So, We must modify the DB which what what my manager tried to avoid.
however, thank you all because you made this clearer for me (crystal )
June 13, 2005 at 9:30 am
We can't provide a solution when none exists... we often have to resort to such workarounds.
June 13, 2005 at 11:50 am
This is not a complex or difficult thing to do, however, you can only accomplish it for the future. Creating an identify key will fill every row with an identity no matter if it did not previously exist. I use an identity field and the ID which normally is the Primary Key. I know you said you couldn't change the data. That happens if either you don't have a primary key or don't have the permissions.
Viewing 12 posts - 1 through 11 (of 11 total)
You must be logged in to reply to this topic. Login to reply