Permalink
Browse files

Add first rev of database schema.

  • Loading branch information...
theory committed Nov 6, 2009
1 parent 6be5e58 commit 2cd8297f7de3b44061fb172052b376c7576a8bca
Showing with 50 additions and 0 deletions.
  1. +50 −0 sql/001-books.sql
View
@@ -0,0 +1,50 @@
+BEGIN;
+
+CREATE TABLE books (
+ isbn ISBN13 PRIMARY KEY,
+ title TEXT NOT NULL DEFAULT '',
+ rating SMALLINT NOT NULL DEFAULT 0 CHECK (rating BETWEEN 0 AND 5)
+);
+
+CREATE TABLE authors (
+ id BIGSERIAL PRIMARY KEY,
+ surname TEXT NOT NULL DEFAULT '',
+ given_name TEXT NOT NULL DEFAULT ''
+);
+
+CREATE TABLE book_author (
+ isbn ISBN13 REFERENCES books(isbn),
+ author_id BIGINT REFERENCES authors(id),
+ PRIMARY KEY (isbn, author_id)
+);
+
+INSERT INTO books
+VALUES ('1587201534', 'CCSP SNRS Exam Certification Guide', 5),
+ ('978-0201633467', 'TCP/IP Illustrated, Volume 1', 5),
+ ('978-0130183804', 'Internetworking with TCP/IP Vol.1', 4),
+ ('978-1-56592-243-3', 'Perl Cookbook', 5),
+ ('978-0735712010', 'Designing with Web Standards', 5)
+;
+
+INSERT INTO authors (surname, given_name)
+VALUES ('Bastien', 'Greg'),
+ ('Nasseh', 'Sara'),
+ ('Degu', 'Christian'),
+ ('Stevens', 'Richard'),
+ ('Comer', 'Douglas'),
+ ('Christiansen', 'Tom'),
+ ('Torkington', 'Nathan'),
+ ('Zeldman', 'Jeffrey')
+;
+
+INSERT INTO book_author
+VALUES ('1587201534', 1),
+ ('1587201534', 2),
+ ('1587201534', 3),
+ ('978-0201633467', 4),
+ ('978-0130183804', 5),
+ ('978-1-56592-243-3', 6),
+ ('978-1-56592-243-3', 7),
+ ('978-0735712010', 8);
+
+COMMIT;

0 comments on commit 2cd8297

Please sign in to comment.