Questions tagged [sql-delete]

The SQL DELETE statement allows you to delete a single row or multiple rows from a SQL table.

The DELETE statement removes one or more rows from a table. A subset may be defined for deletion using a condition, otherwise all rows are removed. Some DBMSs, like MySQL, allow to delete rows from multiple tables with one DELETE statement (this is sometimes called multi-table DELETE).

Use this tag instead of which is too broad.

Reference

3082 questions
22
votes
4 answers

Remove all table rows from SQLite database table

I want to remove all rows that i entered from my SQLite database table. The table name is tbltask. I tried to drop the table and delete * from table, but those are giving me runtime errors. I want to trigger this event in Button OnClickListner…
tharindlaksh
  • 733
  • 2
  • 9
  • 17
22
votes
5 answers

In SQL, is 'FROM' in 'DELETE FROM' optional if you plan to use 'WHERE'?

I'm new to SQL. We have some code that should work on SQL Server 2005/2008, Oracle 10 as well as Sybase. I was writing a script to try to figure out which tables a given stored procedure modifies (but does not drop), e.g insert, update and…
Hamish Grubijan
  • 10,562
  • 23
  • 99
  • 147
22
votes
6 answers

Delete, Truncate or Drop to clean out a table in MySQL

I am attempting to clean out a table but not get rid of the actual structure of the table. I have an id column that is auto-incrementing; I don't need to keep the ID number, but I do need it to keep its auto-incrementing characteristic. I've found…
Doug Molineux
  • 12,283
  • 25
  • 92
  • 144
19
votes
2 answers

Getting the number of affected rows for a SQLite statement using the C API

I'm executing a DELETE statement using the SQLite 3 C API, and I'd like to know how to fetch the number of affected rows. Unfortunately, there is no function such as sqlite3_affected_rows or similar.
netcoder
  • 66,435
  • 19
  • 125
  • 142
18
votes
5 answers

Keep only N last records in SQLite database, sorted by date

I have an SQLite database that I need to do the following: Keep only last N records, sorted by date. How do you do that?
ahmd0
  • 16,633
  • 33
  • 137
  • 233
17
votes
7 answers

How to delete by row number in SQL

I need to delete from row number 475 to 948 due to them being duplicates of rows 1-474. It would be something close to this, I presume, or is there more to it? DELETE FROM dbo.industry WHERE row_number between 475 and 948
Tim Wilcox
  • 1,275
  • 2
  • 19
  • 43
17
votes
5 answers

How do I delete blank rows in Mysql?

I do have a table with more than 100000 data elements, but there are almost 350 blank rows within. How do I delete this blank rows using phpmyadmin? Manually deleting is a tedious task.
Jose H d
  • 195
  • 1
  • 3
  • 7
17
votes
1 answer

Is there a non-commercial alternative to Z.EntityFramework.Extensions?

Entity Framework can be very slow on mass insert/update/delete operations. Even the often suggested tweaks to turn off AutoDetectChanges and/or ValidateOnSaveEnabled does not always help. I have come across the Z.EntityFramework.Extensions on NuGet,…
Michael
  • 938
  • 1
  • 10
  • 34
17
votes
2 answers

Sqlite how delete last added entry of a table

I'm trying to delete the last added entry of a table: DELETE FROM notes ORDER BY created_at DESC LIMIT 1 This just causes the following error: near "ORDER": syntax error Why might I be getting this error? (notes exists and has records in it!)
Markus
  • 3,948
  • 8
  • 48
  • 64
17
votes
1 answer

Using return value from DELETE for UPDATE in Postgres

I need to update a table using a value deleted from another table. The situation is a comment vote scorekeeper similar to the one on SO. I'm using python to work the postgres, but that shouldn't make a difference. query=""" UPDATE comment SET…
JDong
  • 2,304
  • 3
  • 24
  • 42
16
votes
4 answers

How to write a trigger to abort delete in MYSQL?

I read this article but it seems not work for delete. I got this error when tried to create a trigger: Executing SQL script in server ERROR: Error 1363: There is no NEW row in on DELETE trigger CREATE TRIGGER DeviceCatalog_PreventDeletion BEFORE…
JatSing
  • 4,857
  • 16
  • 55
  • 65
16
votes
8 answers

MySQL: how to drop multiple tables using single query?

I want to drop multiple tables with ease without actually listing the table names in the drop query and the tables to be deleted have prefix say 'wp_'
Angelin Nadar
  • 8,944
  • 10
  • 43
  • 53
16
votes
2 answers

DELETE FROM HAVING COUNT(*) in MySQL

Ok so there are couple posts here already on this and fewer still out on the web. I've literally tried every one of them and can not get anything to work. Hopefully someone here can take pity on me :) Here is the data I'm working with. I want to…
RFQ Master
  • 205
  • 1
  • 3
  • 10
15
votes
7 answers

SQL Server 2000 Delete Top (1000)

I have a large SQL Server database with a table at about 45 million records. I am archiving this table, and need to remove all entries greater than two years ago. I have the inserting into my archive table working fine, but I'm having issues with…
Kevin
  • 1,300
  • 5
  • 18
  • 35
15
votes
3 answers

DELETE records which do not have a match in another table

There are two tables linked by an id: item_tbl (id) link_tbl (item_id) There are some records in item_tbl that don't have matching rows in link_tbl. A select which would count their amount would be: SELECT COUNT(*) FROM link_tbl lnk LEFT JOIN…
miloxe
  • 453
  • 1
  • 8
  • 19