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
11
votes
1 answer

What does the output_expression for "DELETE FROM table" do?

I recently ran across an oddity. The following is valid SQL: DELETE FROM customer *; The documentation for PostgreSQL DELETE says the star is a possible value for the output_expression: An expression to be computed and returned by the DELETE…
Barry Brown
  • 20,233
  • 15
  • 69
  • 105
11
votes
4 answers

T-SQL Optimize DELETE of many records

I have a table that can grew to millions records (50 millions for example). On each 20 minutes records that are older than 20 minutes are deleted. The problems is that if the table has so many records such deletion can take a lot of time and I want…
gotqn
  • 42,737
  • 46
  • 157
  • 243
10
votes
3 answers

Sql Server Delete and Merge performance

I've table that contains some buy/sell data, with around 8M records in it: CREATE TABLE [dbo].[Transactions]( [id] [int] IDENTITY(1,1) NOT NULL, [itemId] [bigint] NOT NULL, [dt] [datetime] NOT NULL, [count] [int] NOT NULL, [price] [float] NOT…
adek
  • 223
  • 3
  • 10
10
votes
4 answers

delete rows from multiple tables

I'm trying to use SQL to delete multiple rows from multiple tables that are joined together. Table A is joined to Table B Table B is joined to Table C I want to delete all rows in table B & C that correspond to a row in Table A CREATE TABLE `boards`…
AdRock
  • 2,959
  • 10
  • 66
  • 106
10
votes
5 answers

Delete all rows except 100 most recent ones

I am using MS SQL database and I have a table named "Logs" that looks like this: Records are added here one after another so the table becomes quite big after few days/weeks. What I need to do periodically is a little bit of cleanup. I.e. I…
סטנלי גרונן
  • 2,917
  • 23
  • 46
  • 68
10
votes
4 answers

DELETE data from a table, joining through two tables

I'm working with some rather sensitive data, so I want to be ABSOLUTELY sure I am doing it properly. I am trying to delete the rows in a table that are associated with another table The only way to associate the table is to join through two other…
Derek Adair
  • 21,846
  • 31
  • 97
  • 134
10
votes
4 answers

Python MySQL - SELECTs work but not DELETEs?

I'm new to Python and Python's MySQL adapter. I'm not sure if I'm missing something obvious here: db = MySQLdb.connect(# db details omitted) cursor = self.db.cursor() # WORKS cursor.execute("SELECT site_id FROM users WHERE username=%s",…
Kevin
9
votes
7 answers

SQL delete command?

I am having trouble with a simple DELETE statement in SQL with unexpected results , it seems to add the word to the list??. Must be something silly!. but i cannot see it , tried it a few different ways. All the same result so quite confused. public…
user685590
  • 2,464
  • 5
  • 30
  • 42
9
votes
4 answers

How do I delete duplicate rows and keep the first row?

I made a mistake and I have unwanted duplicates. I have a table with 4 key fields. A1, k1, k2, k3. A1 is auto increment and the primary key. the combination of k1, k2 and k3 is supposed to be unique and I have to delete the duplicate rows before I…
sdfor
  • 6,324
  • 13
  • 51
  • 61
9
votes
3 answers

MySQL: Why is DELETE more CPU intensive than INSERT?

I'm currently taking the course "Performance Evaluation" at university, and we're now doing an assignment where we are testing the CPU usage on a PHP and MySQL-database server. We use httperf to create custom traffic, and vmstat to track the server…
Trond
  • 91
  • 1
  • 2
9
votes
1 answer

Overriding Djangorest ViewSets Delete Behavior

I have defined a Model like this: class Doctor(models.Model): name = models.CharField(max_length=100) is_active = models.BooleanField(default=True) My Serializer: class DoctorSerializer(serializers.ModelSerializer): class Meta: …
9
votes
2 answers

Performance of DELETE with NOT IN (SELECT ...)

I have these two tables and want to delete all authors from ms_author, who are not present in author. author (1.6M rows) +-------+-------------+------+-----+-------+ | Field | Type | Null | Key | index…
Sebbas
  • 399
  • 4
  • 12
9
votes
4 answers

Deleting entire data from a particular column in oracle-sql

Recently I have started learning Oracle-sql. I know that with the help of DELETE command we can delete a particular row(s). So, Is it possible to delete entire data from a particular column in a table using only DELETE command. (I know that using…
Rajeev
  • 442
  • 1
  • 5
  • 18
9
votes
3 answers

Update/delete queries cannot be typed JPA

I'm using the Spring framework for working on training projects. I'm also using JPA and have been having a hell of a time. In my DAO implementation class, I've written: @Override public void deleteEntries(Module mod) { …
user1750824
9
votes
1 answer

INSERT deleted values into a table before DELETE with a DELETE TRIGGER

For some reason I can't find the exact answer that I need. I searched for at last 20 minutes in here. I know it's simple. VERY simple. But I can't fire the trigger for some reason.. I have a table with two columns dbo.HashTags |__Id_|_name_| | 1 |…
Ofir Hadad
  • 1,800
  • 3
  • 26
  • 47