Saturday, February 25, 2012

Copy a table

Hi,
How do I copy a table in my SQL Server 2000?
Actually, I want to copy MyTable to MyTable2 in MyDataBase, and the records
inside too.
Any help will be appreciated.
JasonCREATE TABLE MyTable2 (...) ;
INSERT INTO MyTable2 (...)
SELECT ...
FROM MyTable ;
Or:
SELECT ...
INTO MyTable2
FROM MyTable ;
In this second case, the constraints won't be copied so you'll still have to
create them yourself.
This is development/admin of course. It isn't normally good practice to
create tables at runtime.
David Portas
SQL Server MVP
--
"Jason Huang" <JasonHuang8888@.hotmail.com> wrote in message
news:eqRs4HT1FHA.2964@.TK2MSFTNGP09.phx.gbl...
> Hi,
> How do I copy a table in my SQL Server 2000?
> Actually, I want to copy MyTable to MyTable2 in MyDataBase, and the
> records inside too.
> Any help will be appreciated.
>
> Jason
>|||Hi Jason
David gave you the best technique to copy data from one table to another.
The alternative way of doing this is using DTS.
DTS implements the same technique that David used
best Regards,
Chandra
http://chanduas.blogspot.com/
http://www.SQLResource.com/
---
"David Portas" wrote:

> CREATE TABLE MyTable2 (...) ;
> INSERT INTO MyTable2 (...)
> SELECT ...
> FROM MyTable ;
> Or:
> SELECT ...
> INTO MyTable2
> FROM MyTable ;
> In this second case, the constraints won't be copied so you'll still have
to
> create them yourself.
> This is development/admin of course. It isn't normally good practice to
> create tables at runtime.
> --
> David Portas
> SQL Server MVP
> --
> "Jason Huang" <JasonHuang8888@.hotmail.com> wrote in message
> news:eqRs4HT1FHA.2964@.TK2MSFTNGP09.phx.gbl...
>
>|||Thanks David!
The MicroSoft has the "Copy" and "Paste" in many occasions, why don't they
have the "Copy" "Paste" in the SQL Server? Will this be too stupid or I am
too lazy?
"David Portas" <REMOVE_BEFORE_REPLYING_dportas@.acm.org> glsD:2r6dnX2bm-yyuMreRVnyh
A@.giganews.com...
> CREATE TABLE MyTable2 (...) ;
> INSERT INTO MyTable2 (...)
> SELECT ...
> FROM MyTable ;
> Or:
> SELECT ...
> INTO MyTable2
> FROM MyTable ;
> In this second case, the constraints won't be copied so you'll still have
> to create them yourself.
> This is development/admin of course. It isn't normally good practice to
> create tables at runtime.
> --
> David Portas
> SQL Server MVP
> --
> "Jason Huang" <JasonHuang8888@.hotmail.com> wrote in message
> news:eqRs4HT1FHA.2964@.TK2MSFTNGP09.phx.gbl...
>|||Hi,
There are several reason that microsoft has not provided the facility
of copy and paste because each table has a unique and containe unique
record in terms of name and indexes constraints and many more.
Hope this much is sufficient for u to understand.
from
Doller
Jason Huang wrote:
> Thanks David!
> The MicroSoft has the "Copy" and "Paste" in many occasions, why don't they
> have the "Copy" "Paste" in the SQL Server? Will this be too stupid or I =
am
> too lazy?
> "David Portas" <REMOVE_BEFORE_REPLYING_dportas@.acm.org> =BC=B6=BCg=A9=F3=
=B6l=A5=F3=B7s=BBD:2r6dnX2bm-yyuMreRVnyhA@.giganews.com...[vbcol=seagreen]
ve[vbcol=seagreen]

No comments:

Post a Comment