Primary Key is not AutoGenerating

  • I am new to SQL Server, but have exposure to databases on Mainframe & MS Access, but this is giving me a headache ...

    I am using VB2010 Express and used Project Add New Item to add a SQLCE 3.5 Database to my small program.

    I then created 2 Tables, called "Leagues" & "Teams", by right clicking on the Tables tab in Database Explorer.

    I have used the Solution Explorer to open the DataSet and add a Foreign Key. This is what I now have :

    Table1 : Leagues

    ID - PK, AutoIncrement = True, 1, 1, DataType = System.Int32, Unique = True

    Name - DataType = System.String

    Table2 : Teams

    ID - PK, AutoIncrement = True, 1, 1, DataType = System.Int32, Unique = True

    Name - DataType = System.String

    LeagueID - FK, AutoIncrement = False, DataType = System.Int32, Unique = False

    However, if I right-click on the Table name in Database Explorer & choose Show Table Data, so I can enter a Test entry, it gets rejected with an error message telling me that the ID column cannot be Null ... so why is it not AutoIncrementing ?!? This happens if I try to enter a Test entry into either Table ... BTW, I have read on this site already that some people consider using UniqueKey as a bad thing, but in this case, it is a single user database, so won't be compromised and there is no chance of a lockout, it's just my own small program (that doesn't work !!!) ...

    EDIT : I am now using databases without AutoGenerating the ID, so this topic can be closed ...

Viewing 0 posts

You must be logged in to reply to this topic. Login to reply