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 and paste id column values from excel

Author  Topic 

learning_grsql
Posting Yak Master

230 Posts

Posted - 2013-06-22 : 04:59:00
Hi,

I have a table similar to below :

id | column1 | column2 | column3
1 | values | values | values
2 | values | values | values
5 | values | values | values
6 | values | values | values
7 | values | values | values
9 | values | values | values


I want to copy this table into excel and modify the table and paste back into sql server.

However, when I do that the id values changes to 10, 11, 12 etc. as below :

id | column1 | column2 | column3
10 | values | values | values
11 | values | values | values
12 | values | values | values
13 | values | values | values
14 | values | values | values
15 | values | values | values


Is it possible that id remains the same when I paste it from excel?

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-06-22 : 10:56:18
Likely this is happening because the id column has the identity property. When you paste back are you replacing the existing data, or adding new rows? If you are adding new rows, assuming that my assumption about identity column is correct, the identity values will increase.

Look at the DDL for the table (and post it if you like), which will tell us more. You can see how to get the DDL here: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-06-23 : 02:17:10
if you want to preserve the identity values, you can use IDENTITY_INSERT ON. But for that the original records should not exist anymore. Otherwise it will break the uniqueness of the column.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -