Solved

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

Posted on 2013-12-11
2
232 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
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.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

829 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