Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

copy from one table to another

Posted on 2008-10-05
7
Medium Priority
?
302 Views
Last Modified: 2010-03-19
I want to copy everything from one table to another.
The tables are identical except that the table that is to be copied to has an identity (incremental) column.
How do I do that?
0
Comment
Question by:johnkainn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 37

Expert Comment

by:momi_sabag
ID: 22644014
set identity_insert target_table on
insert into target_table
select * from source_table
set identity_insert target_table off
0
 

Author Comment

by:johnkainn
ID: 22644056
I have a target table with an Id column that is identity column. The name of the target table is y_B.
If I try to use the code you sent I get following error:

Explicit value must be specified for identity column in table 'y_B' either when IDENTITY_INSERT is set to ON or when a replication user is inserting into a NOT FOR REPLICATION identity column.


0
 
LVL 37

Expert Comment

by:momi_sabag
ID: 22644058
do you want to generate id in target table or get them from the source table?
0
How Blockchain Is Impacting Every Industry

Blockchain expert Alex Tapscott talks to Acronis VP Frank Jablonski about this revolutionary technology and how it's making inroads into other industries and facets of everyday life.

 

Author Comment

by:johnkainn
ID: 22644862
I want to generate id in target table.
0
 
LVL 37

Accepted Solution

by:
momi_sabag earned 500 total points
ID: 22644898
ok
so just use
insert into target_table
select * from source_table
0
 
LVL 51

Expert Comment

by:Mark Wills
ID: 22645508
If the only difference between source table and destination table is an additional idenity column in the destination, then you will need to specify the column names...

e.g.  say tbl_destination (id int identity, col1 varchar,col2 int, col3 datetime) and tbl_source (col1 varchar,col2 int, col3 datetime)

then you do...

insert tbl_destination(col1,col2,col3)
select col1,col2,col3
from tbl_source

0
 
LVL 51

Expert Comment

by:Mark Wills
ID: 22645514
Thought I had refreshed before posting. Sorry bout that - please see my posting anyway...
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

by Mark Wills PIVOT is a great facility and solves many an EAV (Entity - Attribute - Value) type transformation where we need the information held as data within a column to become columns in their own right. Now, in some cases that is relatively…
by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question