More Group Sites
Education Books
School Rankings
Jobless Net
Better Home
Enviro++
更好教育论坛
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Share
Options
View
Go to last post Go to first unread
hong  
#1 Posted : Saturday, 8 January 2011 1:03:58 AM(UTC)
hong

Rank: Administration

Reputation:

Groups: AcademicCoachingSchool, admin, Administration, BookSeller, CatholicSchool, CoachingAdult, CoachingProfessional, CoachingSports, ExtraCurriculumCoaching, IndependentSchool, Moderator, MusicTeacher, PrivateSchool, PublicSchool, SelectiveSchool, tutor
Joined: 23/11/2008(UTC)
Posts: 522

The following SQL select query will copy the source table structure to the destination table:
Code:
select *
into <destination table>
from <source table>
where 1=0


Code:
select Top 0 *
into <destination table>
from <source table>


This would not copy keys or indexes.

Alternatively right click on the table in SQL Server Management Studio or Visual Studio, Select Script Table as > Create to > New Query Editor Window, change the the name of the source table to the destination table and modify the scripts if necessary (eg. select part of the fields to copy) and then run the query.

Edited by user Monday, 24 March 2014 9:21:46 PM(UTC)  | Reason: Not specified

Sponsor
hong  
#2 Posted : Sunday, 15 December 2013 2:29:42 PM(UTC)
hong

Rank: Administration

Reputation:

Groups: AcademicCoachingSchool, admin, Administration, BookSeller, CatholicSchool, CoachingAdult, CoachingProfessional, CoachingSports, ExtraCurriculumCoaching, IndependentSchool, Moderator, MusicTeacher, PrivateSchool, PublicSchool, SelectiveSchool, tutor
Joined: 23/11/2008(UTC)
Posts: 522

Related:

Copy / insert from selected columns of source table to destination table if the table schema exists.

Code:
insert into <destination table>
<select statement>

If the table schema and result set are different :

Code:
insert into (<column list>)
<select query>

Similar to above post "SQL how to copy table structure/schema", use the following to create table schema and insert in one execution if the schema doesn't exist:

Code:
select <column list>
into <destination table>
from <source table>

Similarly you can copy / backup an entire database table.

Edited by user Saturday, 27 May 2017 11:30:59 AM(UTC)  | Reason: Not specified

Rss Feed  Atom Feed
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.