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

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

learning_grsql
Posting Yak Master

230 Posts

Posted - 06/22/2013 :  04:59:00  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

3708 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: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 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
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New 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.05 seconds. Powered By: Snitz Forums 2000