Solved

Identity Specification has Changed by it self?

Posted on 2014-02-18
6
263 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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
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.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

830 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