On Thu, 19 Mar 2009 02:54:34 -0700 (PDT), baxy77bax
<b...@hi.htnet.hr> wrote:

>
>hi my question is : if i create table that contains primary key like;
>
>create table TEST (field1 varchar not null primary key);
>
>do i need to create index on it or not?

No, the primary key implies an index will be created
automatically.

>and is it better to create table with a primary key and then import data in
>it or create table without a key , import data and then just create index on
>the table. (which is faster- or should i ask which is the fastest way to
>import data in the table?)

You can't add a primary key afterwards. 

The best way is to create the table with the primary key and
then insert records sorted by the primary key field.
For speed you also have to wrap the INSERT statements in a
transaction (BEGIN; INSERT; ......... INSERT; COMMIT;).

If you want to use the .import command of the SQLite command
line tool, you would sort the import file beforehand on the
primary key column.

>then if i create proper table , is it advisable to order data by 
>column with primary key on it or data with index on it.

In your case (with a primary key on a text column) that
won't make a difference, I think.

>thank you
-- 
  (  Kees Nuyt
  )
c[_]
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to