I have to keep duplicate data in my database so my question is...Is it preferable to keep the duplicate data in the same table and just add a column to identify the original data or I have to create another table to hold the copied data?
-
2By the way, what's the purpose of having duplicate data? Just curious.1000111– 10001112016-08-06 13:03:46 +00:00Commented Aug 6, 2016 at 13:03
-
1i believe he stores money in the dbSzabolcs Dombi– Szabolcs Dombi2016-08-06 13:04:23 +00:00Commented Aug 6, 2016 at 13:04
-
Could you expand a bit on what you're trying to save and why you need the duplicates? The question is a tad too broad to give a useful answer.Mureinik– Mureinik2016-08-06 13:04:48 +00:00Commented Aug 6, 2016 at 13:04
-
1Then I guess it might be the fastest way to become rich overnight :p @DombiSzabolcs1000111– 10001112016-08-06 13:06:07 +00:00Commented Aug 6, 2016 at 13:06
-
Consider reading about database normalization and one to many mappingjarvo69– jarvo692016-08-06 13:08:19 +00:00Commented Aug 6, 2016 at 13:08
2 Answers
I suggest to save the duplicate data in a different table or even a different schema so it won't be confusing to keep working with this table.
Imagine yourself in six months form now trying to guess what are all this duplicate rows for.
In addition those duplicate rows does not reflect the business purpose of this table. It will be nicer to store them in a table named [table_name]_dup or a schema named [schema_name]_dup
Comments
To create a backup you should read this
To duplicate a website with it's content. Bad solution but you still have to make a backup and restore it in a different database.
Duplicate a table in mysql:
CREATE TABLE newtable LIKE oldtable;
INSERT newtable SELECT * FROM oldtable;