Link to home
Start Free TrialLog in
Avatar of curiouswebster
curiouswebsterFlag for United States of America

asked on

SQLite queries needing review

Please review my schema and point out any issues...thanks.

CREATE TABLE IF NOT EXISTS status (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    status TEXT NOT NULL,
    comment TEXT NOT NULL,
    create_date TEXT NOT NULL,
    update_date TEXT NOT NULL
);

INSERT INTO status (status, comment, create_date, update_date) VALUES
('Active', 'The Contact is Active.', datetime('now','localtime'), datetime('now','localtime')),
('Inactive', 'The Contact is no longer Active.', datetime('now','localtime'), datetime('now','localtime')),
('Disabled', 'The Contact has been Disabled.', datetime('now','localtime'), datetime('now','localtime')),
('Unsubscribed', 'The Contact has Unsubscribed from any further contact.', datetime('now','localtime'), datetime('now','localtime')),
('Pending', 'The Contact has been Created but not Activated.', datetime('now','localtime'), datetime('now','localtime'));

CREATE TABLE IF NOT EXISTS contacts (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    email TEXT,
    voterid TEXT,
    fname TEXT,
    lname TEXT NOT NULL,
    street TEXT,
    city TEXT,
    state TEXT,
    zip TEXT,
    cell TEXT,
    company TEXT,
    title TEXT,
    create_date TEXT NOT NULL,
    update_date TEXT NOT NULL,
    statusid INTEGER,
    FOREIGN KEY (statusid) REFERENCES status(id)
);

INSERT INTO contacts (voterid, fname, lname, street, city, state, zip, statusid, create_date, update_date) VALUES
('105008499','JOHN','SMITH','29 ROYAL DR','TALLAHASSEE','FL','30309', 5, datetime('now','localtime'), datetime('now','localtime'));


It works:

User generated image
User generated image 


ASKER CERTIFIED SOLUTION
Avatar of Bembi
Bembi
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of curiouswebster

ASKER

> Personally, I dislike surrogate primary keys.  Every table should have a natural primary key if it properly normalized.

Could you expound on this? What key is a surrogate? And, what is a natural primary key?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I see, you say the Natural Primary Key is email, because it is by definition an Atomic value.

I agree.

But, I will be creating records in the Pending state, with no email address. The email comes in as an update, when the Contact becomes Active. So, it is indeed a required field, only if they register.

I am considering adding an INDEX(email) to the schema, but at the moment, I have no Contact records.

Am I responding to this workflow limitation (no email on INSERT Contact) or do you have a different idea?

Thanks


SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial