I have a table that looks like this
Table1
Id, Name
How can I write a query that delete all rows with duplicate names but kee
The duplicates can be removed with a simple self join query. The below script would do the trick for you.
delete t2
from Table1 t1
join Table1 t2
on t1.Name = t2.Name
where t1.Id < t2.Id
This logic can be used for cases where duplicates need to be removed. We should avoid "cursor" as much as possible as it blocks the table.