Unix Technical Forum

Copy data from one table to another table with change in identity column values

This is a discussion on Copy data from one table to another table with change in identity column values within the SQL Server forums, part of the Microsoft SQL Server category; --> HI, I have a table Create table test(a int identity(1,1), b int) insert into test(b) values(12) insert into test(b) ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-01-2008, 03:39 PM
satish
 
Posts: n/a
Default Copy data from one table to another table with change in identity column values

HI,
I have a table
Create table test(a int identity(1,1), b int)
insert into test(b) values(12)
insert into test(b) values(30)
insert into test(b) values(65)
insert into test(b) values(78)
insert into test(b) values(36)

o/p
a b
1 12
2 30
3 65
4 78
5 36

i need to copy the table into another table with creating the new
table
we had a option
select * into newtable from oldtable
here the data in the oldtable will e copied to new table without
creating new table
but i need to copy the data as shown below with out creating new
table
o/p
a b
11 12
12 30
13 65
14 78
15 36

Thanks,
Satish

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 03-01-2008, 03:39 PM
Roy Harvey
 
Posts: n/a
Default Re: Copy data from one table to another table with change in identity column values

If I understand your question, you want to insert the data from table
test into an already existing table.

INSERT existingtable
SELECT a, b
FROM test

Roy Harvey
Beacon Falls, CT

On Mon, 20 Aug 2007 09:21:30 -0000, satish
<satishkumar.gourabathina@gmail.com> wrote:

>HI,
>I have a table
>Create table test(a int identity(1,1), b int)
>insert into test(b) values(12)
>insert into test(b) values(30)
>insert into test(b) values(65)
>insert into test(b) values(78)
>insert into test(b) values(36)
>
>o/p
>a b
>1 12
>2 30
>3 65
>4 78
>5 36
>
>i need to copy the table into another table with creating the new
>table
>we had a option
>select * into newtable from oldtable
>here the data in the oldtable will e copied to new table without
>creating new table
>but i need to copy the data as shown below with out creating new
>table
>o/p
>a b
>11 12
>12 30
>13 65
>14 78
>15 36
>
>Thanks,
>Satish

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-01-2008, 03:40 PM
Erland Sommarskog
 
Posts: n/a
Default Re: Copy data from one table to another table with change in identity column values

Roy Harvey (roy_harvey@snet.net) writes:
> If I understand your question, you want to insert the data from table
> test into an already existing table.
>
> INSERT existingtable
> SELECT a, b
> FROM test


I guess it should be:

INSERT existingtable
SELECT 10 + a, b
FROM test

since Salish wanted to change the values.


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 03-01-2008, 03:40 PM
Roy Harvey
 
Posts: n/a
Default Re: Copy data from one table to another table with change in identity column values

On Mon, 20 Aug 2007 21:54:50 +0000 (UTC), Erland Sommarskog
<esquel@sommarskog.se> wrote:

>since Salish wanted to change the values.


Thanks for catching that, Erland.

Roy
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 01:07 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com