Keeping track of "prices" in a SQLite database?
My Schema looks like this:
CREATE TABLE items (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
description TEXT NOT NULL,
quantity INTEGER NOT NULL
price TEXT NOT NULL,
category_id INTEGER NOT NULL
);
CREATE INDEX "item_id" ON "items" ("id");
I'm setting price as TEXT
but it probably should be something different.
The data that I need to keep track of is $30/day
. So there is a "cost" part of the number (in USD) and a "per something" part. How should I keep track of this 开发者_开发问答data?
SQLite internally stores everything as text, so don't stress out about your type.
I'd change the column name to "price_per_day", and store it that way. If the item you're storing isn't priced "per day", normalize it to a day, then store it that way.
精彩评论