The problem that i have made something like :

CREATE TABLE t1(  a INTEGER(4) not null unique PRIMARY KEY,  b INTEGER);

That's why it doesn't accept the NULL value for me. But now it's okay.

Thanks
Hatem

----- Original Message ----- 
From: "Peter Pistorius" <[EMAIL PROTECTED]>
To: "Dynamix" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Monday, May 03, 2004 1:36 PM
Subject: RE: [sqlite] Autoincrement of primary key


> 
> SQLITE FAQ:
> 
> 
> (1) How do I create an AUTOINCREMENT field.
> 
> Short answer: A column declared INTEGER PRIMARY KEY will autoincrement.
> 
> Here is the long answer: Beginning with version SQLite 2.3.4, If you
> declare a column of a table to be INTEGER PRIMARY KEY, then whenever you
> insert a NULL into that column of the table, the NULL is automatically
> converted into an integer which is one greater than the largest value of
> that column over all other rows in the table, or 1 if the table is
> empty. For example, suppose you have a table like this: 
> 
> CREATE TABLE t1(
>   a INTEGER PRIMARY KEY,
>   b INTEGER
> );
> 
> With this table, the statement
> 
> INSERT INTO t1 VALUES(NULL,123);
> 
> is logically equivalent to saying:
> 
> INSERT INTO t1 VALUES((SELECT max(a) FROM t1)+1,123);
> 
> For SQLite version 2.2.0 through 2.3.3, if you insert a NULL into an
> INTEGER PRIMARY KEY column, the NULL will be changed to a unique
> integer, but it will a semi-random integer. Unique keys generated this
> way will not be sequential. For SQLite version 2.3.4 and beyond, the
> unique keys will be sequential until the largest key reaches a value of
> 2147483647. That is the largest 32-bit signed integer and cannot be
> incremented, so subsequent insert attempts will revert to the
> semi-random key generation algorithm of SQLite version 2.3.3 and
> earlier.
> 
> Beginning with version 2.2.3, there is a new API function named
> sqlite_last_insert_rowid() which will return the integer key for the
> most recent insert operation. See the API documentation for details.
> 
> 
> -----Original Message-----
> From: Dynamix [mailto:[EMAIL PROTECTED] 
> Sent: Monday, May 03, 2004 12:28 PM
> To: [EMAIL PROTECTED]
> Subject: [sqlite] Autoincrement of primary key
> 
> Greetings,
> 
> is it possible de have an autoincrement feature ?? i want to have
> something like :
> 
> insert into table names (NULL, 'name1'); insert into table names (NULL,
> 'name2'); insert into table names (NULL, 'name3');
> 
> and then id will be 1,2 and 3 ?
> 
> Any help please
> 
> Hatem
> 
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to