Solved

Negative "Primary Keys" show up when openning an SQL Server 2008 database in a Visual basic program.

Posted on 2010-09-20
8
695 Views
Last Modified: 2013-11-26
Why am I getting Negative primary Keys?  The primary key field is set with Identity Spec (Yes). Is Identity (Yes). Identity increment (3), not -3. Identity seed 866731. I am using a data Grid from the table set.  
0
Comment
Question by:jampost
  • 5
  • 3
8 Comments
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33720725
you see identity while you adding new data?or after update?
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33720726
i mean negative identity...
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33720755
It could happen..and it is logic...http://blog.sqlauthority.com/2010/08/19/sql-server-negative-identity-seed-value-and-negative-increment-interval/
"Negative identity values are useful in programming: if you have build part of your database in memory as a dataset and you want to submit the changes back to the server, you cannot be sure of the identity values it will assign (especially in a shared environment). Therefore it is common to use negative identities and increments for the memory dataset and positive ones for the server database. The server does understands that mechanism and will assign correct values (It will take some tricks to refresh these values into the memeory dataset)."
For a more elaborate artikel see: Managing an @@Identity crisis at http://msdn.microsoft.com/en-us/library/ms971502.aspx
0
 

Author Comment

by:jampost
ID: 33721540
jtoutou,
    Thank you for your quick responce. The negative PKs are there before I enter the first record in the dataset. The database & table were all created in the SQL Server Management Studio. The data will be entered through a visual basic program, and that is were the negatives are showing up. I have to admit; I am not a level two or above programer. I assume you are telling me that this is normal. The problem I have is that this is a GUI. There would be no problem if this were behind the scenes. So I guess I need some specificities to correct this.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 18

Accepted Solution

by:
John (Yiannis) Toutountzoglou earned 500 total points
ID: 33722162
As far as i know You do not have to correct anything..."if you have build part of your database in memory as a dataset and you want to submit the changes back to the server, you cannot be sure of the identity values it will assign (especially in a shared environment)"
0
 

Author Comment

by:jampost
ID: 33730426
Jtoutou,
       
          Thank you. I probably need to get acquainted with the world of SQL. This is what I found out. First off you were very helpful in what you told me. I test by clearing all records and starting fresh. Going through the Data Set (The program I am developing in Visual Basic) Row one “Primary Key (“Customer Number” field heading),  I get -1 as the primary key. But…….When I open SQL Server 2008 and check the results in the table it has the test seed I planted (866731).  Now here is the head scratcher (to me anyway). I go back into Visual Studio and Start Debugging (running) the program and (NOW) it has 866731 in place of -1. I suppose it just needed to get refreshed.  Thank you, and I hope you will see my future questions. You have an A grade and 500 points.
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33731798
hi....
very glad i helped you...


P.S You have to accept a solution if you got your answer...:)

0
 

Author Comment

by:jampost
ID: 33735428
I thought I accepted the solution yesterday. It is sort of like the debit card machine at check out. You start to walk away and it has one more yes box to click.  I think I got it this time. Thanks again
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

896 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

17 Experts available now in Live!

Get 1:1 Help Now