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 


SQLDatabases

Avatar of undefined
Last Comment
Bembi
ASKER CERTIFIED SOLUTION
Avatar of Bembi
Bembi
Flag of Germany image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
SOLUTION
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
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
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of curiouswebster

ASKER

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
Avatar of Bembi
Bembi
Flag of Germany image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
SOLUTION
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
SOLUTION
Avatar of Bembi
Bembi
Flag of Germany image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Databases
Databases

Databases are organized collections of data, most commonly accessed through management systems including schemas, tables, queries and processes that allow users to enter and manipulate the information or utilize it in other fashions, such as with web applications or for reporting purposes.

62K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo