Question:
what is SQL query to copy a table from one database into a different?
2010-05-10 07:37:43 UTC
What is the SQL query for copying a table with its contents from one database into a different database. I am using SQL server 2005.
Three answers:
Serge M
2010-05-10 10:53:05 UTC
select * into db_name1.dbo.new_table from db_name2.dbo.old_table
?
2016-11-04 04:49:43 UTC
i could want extra element to help write the question. in specific: how do you tournament up columns from one table with the different? yet enable's anticipate that we've one key characteristic (ok) and a couple of tables (a, b), and we would desire to locate situations the place values (x or y) do no longer tournament up for an analogous key. i could write some thing like this: go with NVL(a.ok, b.ok) tbl_key, a.x A_X, b.x B_X, a.y A_Y, b.y B_Y FROM an entire OUTER connect b ON a.ok=b.ok the place NVL(a.x,'X') <> NVL(b.x,'X') OR NVL(a.y, 'X') <> NVL(b.y,'X') Assuming you %. some fee for those 'X' (consistent) values that's no longer definitely present day interior the database, this could locate all situations the place "a" is lacking the row, or "b" is lacking the row, or "a" and "b" are the two present day yet have diverse information in x or y. If "lacking rows" isn't a controversy, then the (a lot slower) finished OUTER connect can get replaced with inner connect. @M
Abhinav
2010-05-10 08:30:11 UTC
Cant you export the table and then import it into another db


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...