I have a column "ID" in a table, and I need to move that to another table in the same database. How do I do this?

Recommended Answers

All 3 Replies

Create ID column in second table
and run a update query on second table with joining both the tables,so all values in ID column will be update in second table properly
come back and drop column in the first table

Sorry how do you update only one column?

If you want to 'move' a column from one table to another table, both the tables should have a common column to link these 2 tables. First, as Vermadba has mentioned, you have to create a column called "id" in table_2 first. Then, update the second table's "id" column using joins.
For example,

update table_2,table_1 set table_2.id=table_1.id where table_1.counter = table_2.counter

This will update table_2's id column with id values of table_1.
Then delete the column "id" from table_1.
Cheers,
Nav

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.