On Fri, 17 Sep 2010, Igor Tandetnik wrote:

> To: sqlite-users@sqlite.org
> From: Igor Tandetnik <itandet...@mvps.org>
> Subject: Re: [sqlite] UNIQUE PRIMARY KEY on TEXT column?
> 
> Keith Roberts <ke...@karsites.net> wrote:
>> I have the following table to keep a count of the number of
>> times files are downloaded from my website:
>>
>> CREATE TABLE "file_downloads"
>>  (
>>  "record_id" INTEGER PRIMARY KEY,
>>  "filename" char(60),
>>  "dl_count" INTEGER
>>   /* PRIMARY KEY  ("record_id") */
>> );
>>
>> The select statement to get the current download count for a
>> file is:
>>
>> SELECT *
>> from file_downloads
>> where filename = "$dl_file";
>>
>> And the update statement to update the dl_count column is:
>>
>> UPDATE file_downloads set
>> dl_count = "$new_count"
>> where filename = "$dl_file";
>>
>> Would this be an efficient way of doing things?
>>
>> I don't expect to be keeping track of more than 200 files
>> for downloading.
>
> Not really efficient, but with 200 records, you won't notice.
>
>> I was wondering if it is possible to setup the filename 
>> column as a UNIQUE PRIMARY KEY on a TEXT column.
>
> It's UNIQUE or PRIMARY KEY: they don't go together. Yes, 
> you could do either. There could be only one PRIMARY KEY 
> in a table, and you already have one, so you'll have to 
> choose which one you want. On the other hand, you could 
> have an unlimited number of UNIQUE constraints. -- Igor 
> Tandetnik

Thanks Igor.

I think what I really mean is I want a text column with only 
one unique value, that is also indexed.

Also ,I guess the INTEGER PRIMARY KEY column is worth 
keeping in the table, as a matter of course?

Keith

-----------------------------------------------------------------
Websites:
http://www.karsites.net
http://www.php-debuggers.net
http://www.raised-from-the-dead.org.uk

All email addresses are challenge-response protected with
TMDA [http://tmda.net]
-----------------------------------------------------------------

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to