Solved

Identity Specification has Changed by it self?

Posted on 2014-02-18
6
261 Views
Last Modified: 2014-02-19
Hi all!

I have some SQL Server tables on a server and one of the tables uses identity specification as unique ID. When I insert a new record in the table, I use INSERT INTO table (fields) VALUES (some values) and then the system inserts the next ID in the table. It has worked very well for a long time.

'Suddenly' one of the uses get an error that says: column does not allow nulls. INSERT fails. After investigation of the table in question, I discover that identity specification is set to 'no'. I am very sure that I have not changed the value to 'no' and no other has access to the table.

My question is: is it possible that this value can change 'by itself' or could there be circumstaces where the value is changed so ti appear that it has chenged 'by itself'?

After I changed to 'yes', no problems exist.


Best regards
Kim Neesgaard
0
Comment
Question by:Kim Neesgaard
  • 3
  • 2
6 Comments
 
LVL 65

Accepted Solution

by:
Jim Horn earned 250 total points
ID: 39867491
The only logical explanations..
This table was imported from a source to its current location in a manner where the Identity was not in the newly-created table.
Somebody executed a script that did this.
Somebody manually did this, likely to force an insert with a specific value, and forgot to set it back.
Gremlins
0
 

Author Comment

by:Kim Neesgaard
ID: 39867543
Hi Jim!

Thank you for your answer! Actually I can see (and recall) that there has been some copy activities for exactly this table so your first guess seems likely. I certainly not hope for you last suggestion...!


Best regards
Kim Neesgaard
0
 
LVL 75

Assisted Solution

by:Anthony Perkins
Anthony Perkins earned 250 total points
ID: 39869322
The only way that can happen is if you allow someone to rebuild the table.  There is no other way.  You cannot change the IDENTITY attribute without re-creating the table.

So if you want to prevent this from happening in future, tighten your security and do not allow users to use sa (hint hint) and this problem will go away.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:Kim Neesgaard
ID: 39869559
Hi Anthony!

I was allowed to change identity specification from no to yes but perhaps a rebuild was made behind the scenes. In the options 'prevent saving changes that require table re-creation' is not ticked.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 39871977
I was allowed to change identity specification from no to yes but perhaps a rebuild was made behind the scenes.
You are right, behind the scene SSMS is rebuilding the table.  You can see exactly what I mean by "removing" the attribute in the Table Designer but instead of clicking Save, select the icon that reads "Generate Change Script" (it is also under the Table Designer menu.
0
 

Author Comment

by:Kim Neesgaard
ID: 39872627
I have just checked it and it is very visible under Generate Change Script - I didn't know this function. Thank you for elaborate the question!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL date incremented 11 31
Live Storage Vmotion VMs with shared VMDK 10 58
SQL SELECT query help 7 41
create an aggregate function 9 34
Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
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.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

773 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