Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Other SQL Server 2008 Topics
 Primary Key is not AutoGenerating

Author  Topic 

vodkasoda
Starting Member

15 Posts

Posted - 2013-03-04 : 17:40:00
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

Table2 : Teams

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

Name

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

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-03-04 : 23:58:48
why dont you create tables using CREATE TABLE script rather than through wizard?

ALso for inserting data use INSERT t-sql statement rather than trying to add through the grid

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

vodkasoda
Starting Member

15 Posts

Posted - 2013-03-05 : 02:18:01
Well in this instance I am creating (or trying to) 1 single record for Test purposes, I have no intention of typing in every entry when I load the real data ...

I am now using nvarchar & have not specified Unique for my Key & will revisit this in future if I feel the need, for now you can close this question ...
Go to Top of Page
   

- Advertisement -