Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 COPY TABLE

Author  Topic 

getfar
Starting Member

15 Posts

Posted - 2005-11-24 : 05:58:22
Can i copy a table (or its structure) like in Access?

Thanks

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2005-11-24 : 06:05:22
Select * Into <DestinationTableName> From <SourceTableName) Where 1 = 2

NB:
This will just create the table structure as the source table
Wont create any constraint or triggers on the table..

and if you also want to copy the data then remove the where clause..

Sucess Comes to those who Believe in Beauty of their Dream..
Go to Top of Page

surendrakalekar
Posting Yak Master

120 Posts

Posted - 2005-11-24 : 06:06:47
Insted of copy table you can import that table by giving some different name.
If you want to copy structure of one table to another table. In EM. by minimizing the source table (after copy) you can paste it to another table.

Surendra
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-11-24 : 06:56:26
Script the structure of the table and run it. Then

Insert into TargetTable(columns) Select columns from SourceTable

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

getfar
Starting Member

15 Posts

Posted - 2005-11-24 : 09:58:16
I should copy a table but how can i paste the table?
In Access it is possible.

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-11-24 : 23:46:23
Did you try the query I suggested?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

surendrakalekar
Posting Yak Master

120 Posts

Posted - 2005-11-24 : 23:49:17
quote:
Originally posted by getfar

I should copy a table but how can i paste the table?
In Access it is possible.


Do you mean you want to copy a selected table and paste it inculding data ?
In sql server you can not copy a table like access.
Just try all the above posts and use which is suitable for you.....

Surendra
Go to Top of Page

svicky9
Posting Yak Master

232 Posts

Posted - 2005-11-25 : 18:22:28
Then.... can anyone let me know why there is a copy option in the Enterprise manager when you right click the table???

thanks
Vic

Go to Top of Page

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2005-11-26 : 05:57:39
That copy option is just create the script for the table....

so if you copy from there and paste in some word editor software then it will paste the script of the table..

Sucess Comes to those who Believe in Beauty of their Dream..
Go to Top of Page

jfranzone
Starting Member

1 Post

Posted - 2009-03-27 : 12:00:54
I needed to do that same thing, so what I did was:

  • Perform a Data Export of the table to another database on the same server. During the export I modified the mapping so that it output to a different table name than the original.

  • Then perform a Data Import back into the database that I wanted the table in.

  • Finally drop the table from the other database



Admittedly, this is a somewhat contrived solution. It would probably have been a lot simpler to just follow the advise above and:

  • Generate a CREATE script based on the table

  • Modify the script to create a different table name

  • Perform an INSERT from selecting everything from the source table



Jonathan P Franzone
http://www.franzone.com
Blogging, coding, loving, gaming...
Not necessarily in that order.
Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-03-27 : 12:03:59
Any reason you resurrected this thread?
Go to Top of Page

tosscrosby
Aged Yak Warrior

676 Posts

Posted - 2009-03-27 : 14:14:21
quote:
Originally posted by vijayisonly

Any reason you resurrected this thread?



Been a bunch of that lately!

Terry

-- Procrastinate now!
Go to Top of Page
   

- Advertisement -