Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6945201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:24:20+00:00 2026-05-27T13:24:20+00:00

Ok here’s the scenario: we have 1 database that has a table we’d like

  • 0

Ok here’s the scenario:

we have 1 database that has a table we’d like to keep as small as possible. we need to replicate the data in it based on the primary key to another table.

the catch is after we’re finished with the rows (probably a daily process) we will delete the rows from the original database, but keep the data in the new table.

example

10 rows in table A -> 10 rows replicated to table B – total 10 rows in table B

end of day cron deletes all from table A

10 rows in table A -> 10 rows replicated to table B – total 20 rows in table B

my question: is there a way to replicate from A to B without A sending deletes ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T13:24:21+00:00Added an answer on May 27, 2026 at 1:24 pm

    If you are deleting rows, I am assuming they are not here in table A, so what would you be sending them to table B?

    If by deleting you mean ‘marked as deleted’, then simply filter by that condition in your REPLACE statement.

    REPLACE works exactly like INSERT, except that if an old row in the
    table has the same value as a new row for a PRIMARY KEY or a UNIQUE
    index, the old row is deleted before the new row is inserted. See
    Section 12.2.5, “INSERT Syntax”.

    REPLACE is a MySQL extension to the SQL standard. It either inserts,
    or deletes and inserts. For another MySQL extension to standard
    SQL—that either inserts or updates—see Section 12.2.5.3, “INSERT …
    ON DUPLICATE KEY UPDATE Syntax”.

    Note that unless the table has a PRIMARY KEY or UNIQUE index, using a
    REPLACE statement makes no sense. It becomes equivalent to INSERT,
    because there is no index to be used to determine whether a new row
    duplicates another.

    After reading your comment, I understood your problem thusly:

    If A has 10 and B has 0, at first replication B will have 10 and A will have 0 (because you will delete them).

    At next replication, A will have 5 and these won’t be present in B, so you simply copy all from A to B, so B has 15 (again A will be deleted).

    If however, you only want to replicate a subset of rows from A, then you need to apply that filter first (for REPLACE).

    REPLACE will do this for you – except delete the rows from you source table, which you’ll have to do manually. It will keep B updated always.

    mysql> create table A (id INT AUTO_INCREMENT PRIMARY KEY, foo VARCHAR(12));
    Query OK, 0 rows affected (0.05 sec)
    
    mysql> create table B (id INT AUTO_INCREMENT PRIMARY KEY, foo VARCHAR(12));
    Query OK, 0 rows affected (0.06 sec)
    
    mysql> INSERT INTO A VALUES ('','One'),('','Two');
    Query OK, 2 rows affected, 2 warnings (0.00 sec)
    Records: 2  Duplicates: 0  Warnings: 0
    
    mysql> REPLACE INTO B SELECT * FROM A;
    Query OK, 2 rows affected (0.00 sec)
    Records: 2  Duplicates: 0  Warnings: 0
    
    mysql> SELECT * FROM B;
    +----+------+
    | id | foo  |
    +----+------+
    |  1 | One  |
    |  2 | Two  |
    +----+------+
    2 rows in set (0.00 sec)
    
    mysql> UPDATE A SET `foo` = 'One-Up' WHERE `id` = 1; 
    Query OK, 1 row affected (0.04 sec)
    Rows matched: 1  Changed: 1  Warnings: 0
    
    mysql> SELECT * FROM A;
    +----+--------+
    | id | foo    |
    +----+--------+
    |  1 | One-Up |
    |  2 | Two    |
    +----+--------+
    2 rows in set (0.00 sec)
    
    mysql> REPLACE INTO B SELECT * FROM A;
    Query OK, 4 rows affected (0.00 sec)
    Records: 2  Duplicates: 2  Warnings: 0
    
    mysql> SELECT * FROM B;
    +----+--------+
    | id | foo    |
    +----+--------+
    |  1 | One-Up |
    |  2 | Two    |
    +----+--------+
    2 rows in set (0.00 sec)
    
    mysql> DELETE FROM A where id = 1;
    Query OK, 1 row affected (0.00 sec)
    
    mysql> REPLACE INTO B SELECT * FROM A;
    Query OK, 2 rows affected (0.00 sec)
    Records: 1  Duplicates: 1  Warnings: 0
    
    mysql> SELECT * FROM A;
    +----+------+
    | id | foo  |
    +----+------+
    |  2 | Two  |
    +----+------+
    1 row in set (0.00 sec)
    
    mysql> SELECT * FROM B;
    +----+--------+
    | id | foo    |
    +----+--------+
    |  1 | One-Up |
    |  2 | Two    |
    +----+--------+
    2 rows in set (0.00 sec)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's my scenario - I have an SSIS job that depends on another prior
Here is the issue I am having: I have a large query that needs
Here is a simplification of my database: Table: Property Fields: ID, Address Table: Quote
Here's a coding problem for those that like this kind of thing. Let's see
Here is the scenario: I'm writing an app that will watch for any changes
Here is my code (Say we have a single button on the page that
Here is an example feed that I would like to parse: https://gdata.youtube.com/feeds/api/users/aniBOOM/subscriptions?v=2&alt=json You can
Here is my problem...I have a page that loads a list of clients and
Here is an example: I have a file 1.js, which has some functions. I
Here's a basic regex technique that I've never managed to remember. Let's say I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.