tags:

views:

50

answers:

3

Is there an easy way in SQLServer touse data as READ_ONCE? What I mean is, can I set it to delete a row after it has selected it?

+2  A: 

You could do this easily if the data is accessed through a stored procedure. You can select the data into a temp table, delete the data and return the temp. All wrapped in a transaction of course.

Paul Sasik
+5  A: 

Off the top of my head, the only way I can think of would be to restrict all logins to prohiibit any Select access, and only allow access through a stored procedure "FetchMyWhateverData" and then delete the rows as second SQL statement inside the stored proc.

CreateProcedure FetchMyWhateverData
@MyEntityId Integer,
As
Set NoCount On

    Select * From TableName 
    Where Id = @MyEntityId 

    Delete TableName 
    Where Id = @MyEntityId 

    Return 0

-- and adding in the other appropriate infrastructure code of course.

Charles Bretana
Unfortunately, constraints we have been given do not allow us to create procs. This was a solution we had thought of. I apologize for not being more explicit in question.
Adam Lerman
+2  A: 

If you read it with DELETE ... OUTPUT .... This is how queues work.

Remus Rusanu