Tuesday, March 20, 2012

Create a copy of a table in sql server

I have a table I'd like to copy so I can edit it and play around with
the data. How do I create copy of a table in SQl Server?

Thanks,

BillThe easiest method to copy a table with data is SELECT ... INTO:

SELECT *
INTO MyNewTable
FROM MyTable

Note that this method does not copy constraints and indexes.

--
Hope this helps.

Dan Guzman
SQL Server MVP

--------
SQL FAQ links (courtesy Neil Pike):

http://www.ntfaq.com/Articles/Index...epartmentID=800
http://www.sqlserverfaq.com
http://www.mssqlserver.com/faq
--------

"Bill" <billzimmerman@.gospellight.com> wrote in message
news:8da5f4f4.0307221412.380787ad@.posting.google.c om...
> I have a table I'd like to copy so I can edit it and play around with
> the data. How do I create copy of a table in SQl Server?
> Thanks,
> Bill|||Hi

I suggest that you backup the database and restore it as a different
database.

See the following (for move read copy!):

http://support.microsoft.com/defaul...en-us;Q314546#2

John

"Bill" <billzimmerman@.gospellight.com> wrote in message
news:8da5f4f4.0307221412.380787ad@.posting.google.c om...
> I have a table I'd like to copy so I can edit it and play around with
> the data. How do I create copy of a table in SQl Server?
> Thanks,
> Bill|||Isn't that overkill? You'll not only copy the table, but you'll copy
everything else in that database as well!!!!

Thanks,
Brian

John Bell wrote:
> Hi
> I suggest that you backup the database and restore it as a different
> database.
> See the following (for move read copy!):
> http://support.microsoft.com/defaul...en-us;Q314546#2
> John
> "Bill" <billzimmerman@.gospellight.com> wrote in message
> news:8da5f4f4.0307221412.380787ad@.posting.google.c om...
> > I have a table I'd like to copy so I can edit it and play around with
> > the data. How do I create copy of a table in SQl Server?
> > Thanks,
> > Bill

--
================================================== =================

Brian Peasland
dba@.remove_spam.peasland.com

Remove the "remove_spam." from the email address to email me.

"I can give it to you cheap, quick, and good. Now pick two out of
the three"|||if you're moving it from one database to another on the same server, i
would use DTS and "copy object." if you're moving it to another
server this method will sometimes fail.

i'm not sure but i think it has something to do with object
permissions granted to logins that exist on the source server but do
not exist on the destination server. if it's all on the same server
it's a non-issue. i'm pretty sure this will also bring over your
indexes, constraints, etc.|||When playing mistakes can be made!

John

"Brian Peasland" <dba@.remove_spam.peasland.com> wrote in message
news:3F1E8D4A.D0B2AB56@.remove_spam.peasland.com...
> Isn't that overkill? You'll not only copy the table, but you'll copy
> everything else in that database as well!!!!
> Thanks,
> Brian
> John Bell wrote:
> > Hi
> > I suggest that you backup the database and restore it as a different
> > database.
> > See the following (for move read copy!):
> > http://support.microsoft.com/defaul...en-us;Q314546#2
> > John
> > "Bill" <billzimmerman@.gospellight.com> wrote in message
> > news:8da5f4f4.0307221412.380787ad@.posting.google.c om...
> > > I have a table I'd like to copy so I can edit it and play around with
> > > the data. How do I create copy of a table in SQl Server?
> > > > Thanks,
> > > > Bill
> --
> ================================================== =================
> Brian Peasland
> dba@.remove_spam.peasland.com
> Remove the "remove_spam." from the email address to email me.
>
> "I can give it to you cheap, quick, and good. Now pick two out of
> the three"sql

No comments:

Post a Comment