Delete rows from a table except a MYSQL amount

1

I have in a table the columns:

codigo, cliente, token_md, val, cartcodigo, clientenome, clientesobrenome, clientecpf, clientenascimento

I need to delete exactly 46,550 rows from this table, with no worries of order.

    
asked by anonymous 06.06.2018 / 20:37

1 answer

0

Deleting using LIMIT can not limit the number of rows, one way to do this is to create a temporary table by limiting the number of rows, and then we remove the original table and recreate it based on the temporary one. So:

1. Creating the temporary table:

CREATE TABLE tabela_temporaria
  SELECT codigo
        ,cliente
        ,token_md
        ,val
        ,cartcodigo
        ,clientenome
        ,clientesobrenome
        ,clientecpf
        ,clientenascimento
    FROM tabela
   LIMIT > 46550

2. Then we removed the original table:

DROP TABLE tabela;

3.Receive temporary table based on temporary

CREATE TABLE tabela
  SELECT codigo
        ,cliente
        ,token_md
        ,val
        ,cartcodigo
        ,clientenome
        ,clientesobrenome
        ,clientecpf
        ,clientenascimento
    FROM tabela_temporaria
    
06.06.2018 / 22:03