Running an .sql script to generate a database

I’ve been messing around with SQLITE3 databases again, and just created my very first one. It’s called db01.db3 – how original! First I created a little .sql script where I could type in my commands all at once. It’s called michtest.sql. It looks like this:

-- This is my very first SQL database script
-- created:  2010/02/10
-- author:  Michelle W

CREATE TABLE survey_date (
       a_key INTEGER PRIMARY KEY,
       Year  INTEGER,
       Month INTEGER,
       Day   INTEGER,
       Hour  INTEGER,
       Minute	INTEGER,
       Second	DECIMAL(4,1)
       );

Yup, nothing but an empty, meaningless table.

To get it to run and populate an actual database file, I just had to run the following command:

$ sqlite3 db01.db3 < michtest.sql

The code runs, the database file is either created or updated. To see what's in it, I can just run:

$ sqlite3 db01.db3
sqlite> .tables
survey_date

  1. No comments yet.

  1. No trackbacks yet.