Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sql delete row error

I am trying to delete a row in sql server management studio 2012 but an error appears:

sql error

No rows were deleted

A problem occurred attempting to delete row 2 Error Source: Microsoft.SqlServer.Management.DataTools Error Message: The row value(s) updated or deleted either do not make the row unique or they alter multiple rows(2 rows)

Is there a way to fix error that without typing any query?

like image 701
Mickeljh Avatar asked Dec 17 '15 21:12

Mickeljh


People also ask

How do I delete a row in SQL query?

This is the basic syntax for using the DELETE query: DELETE FROM table_name WHERE condition of which row(s) to delete; If you want to delete one row from the table, then you have to specify a condition.

Why can't I delete a table in SQL?

The reason SQL won't let you drop a table in this situation is because the allocation pages/extent chain appears to be damaged or cross-linked in some way. So SQL Server thinks that there is actually data from other tables in pages/extents belonging to the problem object.


1 Answers

Thanks @Hani

I had the same problem (actually a table with a Unique ID, but with some rows accidentally duplicated including the "unique ID" so I couldn't delete the duplicate rows), and your advise helped me solved it from the SQL Server Management GUI.

  1. I used the GUI interface to "edit top 200 rows" in table.
  2. I then added a filter in the SQL Criteria pane which brought up just my two duplicate rows. (This was were I couldn't deleted one of the rows from).
  3. Inspired by your comment, I opened the SQL Pane and changed the:

SELECT TOP(200)...{snip my criteria created by filter}

to instead read:

SELECT TOP(1)...{snip my criteria created by filter}

  1. I was then able to "Execute SQL" the tweaked SQL.
  2. I was then able to use the interface to Delete the single line shown (no warnings this time).
  3. Re-running the SQL Criteria with 200 rows confirmed that just one row had been successfully deleted and one remained.

Thanks for the help, this proved to be the perfect blend of GUI and SQL code for me to get the job done safely and efficiently.

i hope this helps others in a similar situation.

like image 173
Mike Avatar answered Sep 29 '22 12:09

Mike