Create Sample Database


For our examples we are going to use an SQLite database. It is simple to install as it comes within DBD::SQLite, its own database driver and it provides everything we need for our examples.

Actually SQLite is a very good database useful in many applications that don't require concurrent write access to the database frequently.

In order to create the sample database run examples/dbi/create_sample.pl


examples/dbi/sample.sql
CREATE TABLE people (
    id       INTEGER PRIMARY KEY,
    fname    VARCHAR(100), 
    lname    VARCHAR(100), 
    email    VARCHAR(100) UNIQUE NOT NULL,
    pw       VARCHAR(20) NOT NULL
);

INSERT INTO people (fname, lname, email, pw)
        VALUES  ('Foo',  'Bar',   'foo@bar.com',    'secret');
INSERT INTO people (fname, lname, email, pw) 
        VALUES  ('Peti', 'Bar',   'peti@bar.com',   'real secret');
INSERT INTO people (fname, lname, email, pw) 
        VALUES  ('Moo',  'Bar',   'moo@bar.com',    'no secret');
INSERT INTO people (fname, lname, email, pw) 
        VALUES  ('Foo',  'Bar',   'bar@perl.org',   'obFoo');
INSERT INTO people (fname, lname, email, pw) 
        VALUES  ('Foo',  'Berry', 'berry@perl.org', 'yrreB');
 
CREATE TABLE accounts (
    id       INTEGER PRIMARY KEY,
    owner    INTEGER UNIQUE NOT NULL, 
    amount   INTEGER
);

INSERT INTO accounts (owner, amount) VALUES (1, 1000); 
INSERT INTO accounts (owner, amount) VALUES (2, 2000); 
INSERT INTO accounts (owner, amount) VALUES (3, 0); 


CREATE TABLE cds (
    id       INTEGER PRIMARY KEY,
    title    VARCHAR(100),
    artist   INTEGER
);