T-SQL UPDATE TOP (1) statement to distinguish non-unique rows

Occasionally I need to update or delete rows from a heap table (meaning it contains no primary key). When dark forces align, all the columns have duplicate data. This makes DELETE or UPDATE trivially more tricky than using a simple WHERE clause, but I find myself needing to double-check the syntax. The sticky point is the parentheses surrounding the row count, which is different than my similar usage on the SELECT statement. I am recording it here for future reference:

— to delete only one of several rows that have no data to distinguish each row:
–UPDATE TOP (1) conformal_coat set thickness=’112150102′ where serial_number_id =’54476092-B176-4B46-907C-CA7DABE3FB83′

I did not check whether this also works on the DELETE statement, but it will be easy to check the next time this occurs. After UPDATING a column of one of the rows’ values to be unique, the unique value can be added to a WHERE clause to update only the single row desired.
Usually, treatment for this reproductive disorder is prescribed after free sample cialis analyzing the right cause of problem. Yes, there can be side effects ordering levitra for those who are suffering from one or the other kind of behavioral issues. If you want to become a better you, you must take advantage of what super cheap viagra nature has to offer. Kamagra is mainly taken orally with a glass sildenafil tablets uk of water and even if-God forbid-on the toilet.
–delete from conformal_coat where thickness=’112150102′ and serial_number_id =’54476092-B176-4B46-907C-CA7DABE3FB83′

 

See also: http://stackoverflow.com/questions/2909118/update-a-single-row-with-t-sql

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.