Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am new to this site, I have one major question of data migration, I apologize before hand if the question is too silly.

I have two data base on one server, I have one table with the same schema on both the databases, and the database is not primary, I have made it composite, that is , always I have to provide two keys instead of one key to fetch a tuple.

Now I have to migrate specific data from one database to another let say only those data which has 'batch id 1258' and batch id is included to make the entire database as composite that is; batch id and any table's primary key (batch id + table A primary key = composite key of Table A ) which is also referred as FK( FK is also composite ) to other table.

Now what I am supposed to do to migrate the all the data related to batch id 1258 only to another database and not other.

Should I write certain script to copy the entire data and insert it into the other database? or anything else, right now I am clueless, but I want to migrate these specific data anyhow.

Can we have some light on this, so that I can proceed with this!

I am using PostgrSQL 9.0.13

Example of Composite Key : enter image description here

Table student was primary as only id field was there to fetch any record but I made it composite that is id + batch_id, and now both are used to fetch the records; whereas table batch have the id field which is used for the all tables in my Database to make it composite that is any random table_id + batch_id, as the table batch has batch specific data, which means it holds the batch year and which is repeated in the student table record.

And now I want only specific data to be migrated, which means the students who belong to batch 1258 from student table to another database on the same server.

share|improve this question
It is not quite clear what you ask here. Could you please show the table structure itself? Then it will be immediately clear what is the composite key. – dezso Oct 21 '13 at 10:50
I have just updated the question with appropriate table structure explaining the composite key. – Pratibha Oct 21 '13 at 12:06
What is the idea behind using the composite PK? I can't really imagine the use case where a student is identified by a batch. As you have a serial for the ID, it does not add to the uniqueness, either. To me this looks like some design mistake. – dezso Oct 23 '13 at 11:04
Student table is in more than 2 databases on my server, I want to perform certain test before I push my code live for only certain batch (1258), for that I would like to pull entire data of student from any of the database to the another only for a single batch, if I pull over the data with PK, it will result in huge bad data, so I made it composite PK, so that the combination will not violate any of the constraints and create bad data. We can see it in the terms of stable environment and the test environment. – Pratibha Oct 23 '13 at 12:00
If I understand you correctly then you should use a junction table for matching students to batches. – dezso Oct 23 '13 at 15:37

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.