Solved

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

Posted on 2013-12-11
2
226 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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

763 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

11 Experts available now in Live!

Get 1:1 Help Now