Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2013-12-11
2
Medium Priority
?
251 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 11

Accepted Solution

by:
Guru Ji earned 2000 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

604 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