Solved

Changing a column to "Is Identity = Yes" when data exists in the column.

Posted on 2013-12-11
2
228 Views
Last Modified: 2013-12-11
Hello Experts,

I have imported data from Excel into MS SQL Server 2012 Express. All of the records have IDs already assigned to them. My task was and is to take the Excel data and normalize it into various tables and basically build a database. I went about this by breaking out the data into Excel sheets and manually assigning IDs to related the data together. Now that I am finished with that process I am ready to import into MS SQL Server, but I see that what I intended to be the Primary Key for each table, I cannot set the Is Identity = Yes attribute. Is that because there is already data in the table? Is there a way to do this? What is your advice for me? I suppose I could just add a new column to each table once imported and make it the Primary Key and set Identity = Yes, but I don't know if that's they best answer.

Thank you,
Riverwalk
0
Comment
Question by:RiverWalk
2 Comments
 
LVL 11

Accepted Solution

by:
Guru Ji earned 500 total points
ID: 39712138
Check your column data type for ID you are importing from excel.

If it is varchar then you can't change it to identity column.

To change it to identity column, it should have int data type.
0
 

Author Comment

by:RiverWalk
ID: 39712351
In Excel, the column is the "number" format, but once it comes into SQL Server it is of data type, "float". I have set the decimal setting to zero in Excel, but it still comes into MS SQL Server as float. However, your comment prompted me to try something that I thought I tried before but was not sure if I really followed through with it. I thought I tried changing the field from float to int in SSMS, but I guess I did not, because I just tried it and it worked, After changing to int and saving it, then I was able to set Is Identify = Yes. Great!

I think I was afraid that changing the data type in SQL Server would drop the table and cause me to lose data. But it didn't.

Thank you!

Riverwalk
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Datetime function 12 81
SQL Query 34 79
My Query is not giving correct result. Please help 5 24
T-SQL: Nested CASE Statements 4 21
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

948 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now