Sunday, February 19, 2012

Copy table to a new database

Hi, I have a old DB "TrackOLD" and have instald a new "TrackNEW"
I need som data in the "TrackOLD" DB
How do I copy a table from "TrackOLD" to "TrackNEW"?
Both DB are on the same server.
Thanksmsnews.microsoft.com wrote:
> Hi, I have a old DB "TrackOLD" and have instald a new "TrackNEW"
> I need som data in the "TrackOLD" DB
> How do I copy a table from "TrackOLD" to "TrackNEW"?
> Both DB are on the same server.
> Thanks
>
To insert the "old" data into a new table in the "new" DB, do this:
SELECT *
INTO NewDB.dbo.NewTable
FROM OldDB.dbo.OldTable
(note that this WILL NOT bring over indexes, defaults, triggers,
constraints, or anything else related to the table, JUST the data)
To insert the "old" data into an existing table in the "new" DB, do this:
INSERT INTO NewDB.dbo.NewTable
SELECT *
FROM OldDB.dbo.OldTable
(you may encounter problems due to trying to insert IDENTITY values - if
so, replace the SELECT * with the explicit list of columns that you want
to copy over, excluding the IDENTITY column)
Tracy McKibben
MCDBA
http://www.realsqlguy.com|||Thanks, I have copy all the data I need.
Gjerde
"Tracy McKibben" <tracy@.realsqlguy.com> wrote in message
news:45A4E831.7020904@.realsqlguy.com...
> msnews.microsoft.com wrote:
> To insert the "old" data into a new table in the "new" DB, do this:
> SELECT *
> INTO NewDB.dbo.NewTable
> FROM OldDB.dbo.OldTable
> (note that this WILL NOT bring over indexes, defaults, triggers,
> constraints, or anything else related to the table, JUST the data)
> To insert the "old" data into an existing table in the "new" DB, do this:
> INSERT INTO NewDB.dbo.NewTable
> SELECT *
> FROM OldDB.dbo.OldTable
> (you may encounter problems due to trying to insert IDENTITY values - if
> so, replace the SELECT * with the explicit list of columns that you want
> to copy over, excluding the IDENTITY column)
>
> --
> Tracy McKibben
> MCDBA
> http://www.realsqlguy.com

No comments:

Post a Comment