/    Sign up×
Community /Pin to ProfileBookmark

Mysql Data move

How to move data one table to another table. and old table data delete.
I makes account management software and this software i want end of the year the user move his transaction full data move other table and he start new blank table and start transaction. and old table using other work.
i want php code i could not make this.

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJan 30.2020 — Well, first thing I would suggest is that this is not necessary, and could end up being an annoyance later if you ever want to pull historical data for a user across multiple years. If the table has some date or timestamp field for each transaction, all you need to do is add where date_column between '2020-01-01' and '2020-12-31' to get transactions for only this year. Assuming the table is properly indexed, it should not affect performance as it grows, in case that was part of your reasoning.

If you decide you still want to do it, the basic way to move data would be:
<i>
</i>insert into new_table (col1, col2, ... colN)
select col1, col2, ... colN from old_table;

Then you could use truncate to clear the old table -- preferably after making sure the new one was correctly populated.
Copy linkTweet thisAlerts:
@ginerjmJan 30.2020 — I agree with Nogdog. Moving a full set of data out of your normal table means that your existing code would not work for any kind of all-encompassing queries that wanted to see historical data.

Adding a key or using an existing date column would be the way to solve your dilemma unless you have a vital reason for doing what you propose.
×

Success!

Help @hasib2020 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...