Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Duplicate all rows in sql database table

Tags:

sql

I have a table which contains house details called property. I am creating a localised application, and I have a db table called propertylocalised. In this table is held duplicates of the data and culture column e.g.

key  culture propertyname

1     en       helloproperty

1     fr       bonjourproperty

At the moment I have all my en culture inserted but I want to duplicate all of those rows and then for every other row insert fr into culture.

I obviously only want to do this once, for the purpose of setting up the localisation.

Thanks

Andy

like image 454
weaveoftheride Avatar asked Apr 21 '10 06:04

weaveoftheride


People also ask

Can SQL table have duplicate rows?

Duplicate rows are a fundamental part of the SQL model of data because the SQL language doesn't really try to implement the relational algebra. SQL uses a bag (multiset)-based algebra instead.

How do you replicate rows in SQL?

To select duplicate values, you need to create groups of rows with the same values and then select the groups with counts greater than one. You can achieve that by using GROUP BY and a HAVING clause.

How do I keep duplicate rows in SQL?

Keep duplicate rows Select a column by clicking the column header. To select more than one column contiguously or discontiguously, press Shift+Click or CTRL+Click on each subsequent column. Select Home > Keep Rows > Keep Duplicates.

Can there be duplicate rows in database?

Generally, duplicate rows are not always allowed in a database or a data table. The regular practice of many companies is to clean their data from such occurrences. However, they are sometimes encountered, especially in new, raw, or uncontrolled data.


2 Answers

INSERT INTO table 
SELECT 'fr', propertyname
FROM table

assuming you want to duplicate all the existing records which are all 'en'

like image 53
dkretz Avatar answered Oct 10 '22 17:10

dkretz


insert into propertylocalised select key,'fr'propertyname from propertylocalised  where culture = 'en'
like image 41
stacker Avatar answered Oct 10 '22 15:10

stacker