On 2015-03-05 04:29 PM, Oskar Schneider wrote:
> Yes i already wonder why this table creating looks so much different from the 
> other table, because i needed many loops.This is the new 
> version:db.execute("""CREATE TABLE IF NOT EXISTS TRAVELDAYS
>         (TaskUID INTEGER PRIMARY KEY  AUTOINCREMENT,
>         Day                     INT  NOT NULL,
>         Value                   INT  NOT NULL);""")Is it enough that TaskUID 
> is primary key or should (TaskUID, Day) be primary key for faster look up?

Depends... how will you look up the values? If searches and lookups will 
mostly be done by TaskUID+Day, then definitely create the PK over both. 
The only consideration is that tables with few columns and millions of 
rows usually carry heavy loads with larger Indices. Another option is to 
create the PK over both and declare the table WITHOUT ROWID which should 
render it less fat.

Example:

CREATE TABLE IF NOT EXISTS TRAVELDAYS (
   TaskUID INT,
   Day INT  NOT NULL,
   Value INT  NOT NULL,
   PRIMARY  KEY (TaskUID, Day)
) WITHOUT ROWID;


You don't need an autoincrement, it will be always unique. Unless you 
plan to delete entries and wishes their old TaskUIDs never to be used 
again. But if this is the case, you should consider using a foreign key 
reference to whatever table you have that keeps a list of the tasks 
(assuming there is such a thing) - or maintain your own UID fountain.


Reply via email to