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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 copy and paste id column values from excel
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Posting Yak Master

230 Posts

Posted - 06/22/2013 :  04:59:00  Show Profile  Reply with Quote

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
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 06/22/2013 :  10:56:18  Show Profile  Reply with Quote
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:
Go to Top of Page

Very Important crosS Applying yaK Herder

52326 Posts

Posted - 06/23/2013 :  02:17:10  Show Profile  Reply with Quote
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
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000