Wrox Home  
Search P2P Archive for: Go

  Return to Index  

sql_language thread: Re: how to create a table with autonumber and primary key?


Message #1 by "Hal Harris, Jr." <halharris@y...> on Sun, 6 Oct 2002 23:15:00
Try this:
CREATE TABLE App (Id COUNTER CONSTRAINT PrimaryKey PRIMARY KEY,FirstName 
TEXT(50), and the rest of your fields)


> > i use Access2000
> > my sql statement is like this
> > strSQL = "CREATE TABLE Janet ([ID] LONG PRIMARY KEY, [NAME] 
> > VARCHAR(50));"
> > objRS.Open strSQL, objConn
> > 
> > after executed,
> > i want to insert data:
> > strSQL = "INSERT INTO Janet([NAME]) VALUES('Smith');"
> > objRS.Open strSQL, objConn
> > 
> > then a message was appeared:
> > primary key [ID] cann't contain null value.
> > 
> > i thought primary key field is autonumbered automatically each time i 
> > insert new record.
> > 
> > my question is:
> > how do we create a autonumber field with primary key?
> > thanks in advance
> > 
> 
> I think you have to explicitly declare the field as an autonumber field 
> with Access.  I may be wrong, so if anyone knows better, please speak up!
> 
> I don't know if using SQL will work, but if you use an ADO connection 
with 
> VB6 interface, you should be able to add new records via the control, 
and 
> the new record would *definitely* be autonumbered.

  Return to Index