Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to delete rows by calling its row number

I have this data stored in the SQL Server

enter image description here

How can I delete the first three rows by calling the row number found in the left (1,2,3)?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can’t. That row number is not tangible and is nothing more than the order the results were returned in. SQL does not guarantee order of data, so there is no rule that says if you run the same query 20 times, you’ll get the same results at 1,2, and 3 each time. That’s not to say you won’t get them same results, they’re just not guaranteed. You need to delete using a column that actually exists as part of the table definition, such as F1, F2, etc…

As others have suggested in the comments, try to clean up the data before you import it into SQL Sever. You have a few options.

  1. Delete the rows from the file before importing.
  2. Configure the Import Wizard correctly to exclude those rows.

Helpful link

https://docs.microsoft.com/en-us/sql/relational-databases/import-export/import-data-from-excel-to-sql?view=sql-server-ver15

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading