Solved

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

Posted on 2010-09-20
8
709 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
[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
  • 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

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
 
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

Turn Insights into Action

Communication across every corner of your business is essential to increase the velocity of your application delivery and support pipeline. Automate, standardize, and contextualize your communication processes with xMatters.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
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.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

691 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