head	1.8;
access;
symbols;
locks; strict;
comment	@# @;


1.8
date	99.01.27.18.39.11;	author hartmans;	state Exp;
branches;
next	1.7;

1.7
date	99.01.25.20.12.16;	author jemorris;	state Exp;
branches;
next	1.6;

1.6
date	99.01.25.06.15.19;	author jemorris;	state Exp;
branches;
next	1.5;

1.5
date	99.01.25.05.40.42;	author jemorris;	state Exp;
branches;
next	1.4;

1.4
date	99.01.25.01.23.20;	author jemorris;	state Exp;
branches;
next	1.3;

1.3
date	99.01.25.01.22.33;	author jemorris;	state Exp;
branches;
next	1.2;

1.2
date	99.01.23.23.38.12;	author jemorris;	state Exp;
branches;
next	1.1;

1.1
date	99.01.23.23.36.11;	author jemorris;	state Exp;
branches;
next	;


desc
@Sample schema for the class; problem domain is a library.
@


1.8
log
@Fix schema bugs
@
text
@-- Amended 01/27/1999 to fix bugs

-- the library's books; some info about them is in other tables
create table books (
  bookid      integer
    constraint bookid_primary primary key,
  title       varchar(255) not null, 
    --should really be table like authors
  series      varchar(255), 
    -- should really be table like authors
  position    integer,  -- where in series
  checkouts   integer default 0 not null -- number of times checked out
);
create sequence bookid_seq;


-- the author(s) of each book; must be a separate table since each
-- book could have multiple authors (so multiple rows here)
create table authors (
  bookid      integer
  constraint authors_bookid_exists
    foreign key(bookid) references books(bookid),  
  author      varchar(255),
  constraint authors_primary primary key (bookid, author)
);


-- library members / book borrowers; some are librarians
create table members (
  memberid    integer, -- encoded in membership card
  constraint members_primary primary key (memberid),
  name_prefix varchar(255),
  name_first  varchar(255),
  name_middle varchar(255),
  name_last   varchar(255),
  name_suffix varchar(255),
  email       varchar(255),
  credit      integer default 0 not null,  -- fine credit, in cents
  mem_start   date not null,
  mem_end     date not null,
  mem_lib     integer not null, -- librarian who sold the membership
  constraint mem_lib_exists
    foreign key(mem_lib) references members(memberid),
  librarian   integer -- librarian bits; null for non-librarians
);
create sequence memberid_seq;























-- information about all the individual copies of a book; again, this
-- is a separate table since most books will have multiple rows here.
-- we assume each copy gets its own barcode and key on that.
create table copies (
  barcode     integer,
  constraint copies_primary primary key (barcode),
  bookid      integer not null,
  constraint copies_bookid_exists 
    foreign key(bookid) references books(bookid),
  circ        integer default 0 not null,  -- does this book circulate?
  constraint circ_boolean check (circ in (0, 1)),
  out_to      integer,     -- who has this checked out?
  constraint out_to_exists 
    foreign key (out_to) references members(memberid),
  out_by      integer not null, -- what librarian checked it out?
  constraint out_by_exists
    foreign key (out_by) references members(memberid),
  due_by      date,
  obtained    date not null
);
create sequence barcode_seq;


-- library fines incurred 
create table fines (
  fineid      integer,
  constraint fines_primary primary key (fineid),
  memberid    integer not null,
  constraint fines_memberid_exists
    foreign key(memberid) references members(memberid),
  librarian   integer not null,
  constraint fines_librarian_exists
    foreign key(librarian) references members(memberid),
  amount      integer not null, -- in cents
  reason      varchar(255) not null,
  incurred    date not null,
  paid        date
);
create sequence fineid_seq;


@


1.7
log
@add blank lines so pagebreak falls betweent ables
@
text
@d1 1
d12 1
a12 1
  checkouts   integer not null default 0 -- number of times checked out
d23 1
a23 1
  author      varchar(255)
d38 1
a38 1
  credit      integer not null default 0,  -- fine credit, in cents
d79 1
a79 1
  circ        integer not null default 0,  -- does this book circulate?
d83 1
a83 1
    foreign key out_to references members(memberid),
d86 1
a86 1
    foreign key out_by references members(memberid),
@


1.6
log
@more comments
@
text
@d48 21
d108 2
@


1.5
log
@when authors(bookid) is not null, authors(author) should be not null
also; once primary key is used, it's redundant for both
@
text
@d2 1
d11 1
a11 1
  checkouts   integer not null default 0
d16 2
d27 1
d37 1
a37 1
  credit      integer not null default 0,  -- in cents
d48 3
d57 1
a57 1
  circ        integer not null default 0,
d59 1
a59 1
  out_to      integer not null,
d62 1
a62 1
  out_by      integer not null, -- should be librarian!
d71 1
@


1.4
log
@move long comments to next line so they don't run off slide
@
text
@d16 1
a16 1
  bookid      integer not null
d19 1
a19 1
  author      varchar(255),
@


1.3
log
@tabs to spaces
@
text
@d5 4
a8 2
  title       varchar(255) not null, --should really be table like authors
  series      varchar(255), -- should really be table like authors
@


1.2
log
@correct type; eliminate some cookie fields for simplicity
@
text
@d3 6
a8 6
	bookid 	   integer
	  constraint bookid_primary primary key,
	title 	   varchar(255) not null, --should really be table like authors
	series 	   varchar(255), -- should really be table like authors
	position   integer,  -- where in series
	checkouts  integer not null default 0
d14 5
a18 5
	bookid	   integer not null
	constraint authors_bookid_exists
	  foreign key(bookid) references books(bookid),	
	author	   varchar(255),
	constraint authors_primary primary key (bookid, author)
d23 15
a37 15
	memberid   integer, -- encoded in membership card
	constraint members_primary primary key (memberid),
	name_prefix varchar(255),
	name_first  varchar(255),
	name_middle varchar(255),
	name_last   varchar(255),
	name_suffix varchar(255),
	email	    varchar(255),
	credit	    integer not null default 0,  -- in cents
	mem_start   date not null,
	mem_end	    date not null,
	mem_lib     integer not null, -- librarian who sold the membership
	constraint mem_lib_exists
	  foreign key(mem_lib) references members(memberid),
	librarian   integer -- librarian bits; null for non-librarians
d43 15
a57 15
	barcode    integer,
	constraint copies_primary primary key (barcode),
	bookid	   integer not null,
	constraint copies_bookid_exists 
	  foreign key(bookid) references books(bookid),
	circ	   integer not null default 0,
	constraint circ_boolean check (circ in (0, 1)),
	out_to	   integer not null,
	constraint out_to_exists 
	  foreign key out_to references members(memberid),
	out_by	   integer not null, -- should be librarian!
	constraint out_by_exists
	  foreign key out_by references members(memberid),
	due_by	   date,
	obtained   date not null
d63 12
a74 12
	fineid	   integer,
	constraint fines_primary primary key (fineid),
	memberid   integer not null,
	constraint fines_memberid_exists
	  foreign key(memberid) references members(memberid),
	librarian  integer not null,
	constraint fines_librarian_exists
	  foreign key(librarian) references members(memberid),
	amount	   integer not null, -- in cents
	reason	   varchar(255) not null,
	incurred   date not null,
	paid	   date
@


1.1
log
@Initial revision
@
text
@a30 7
	address1    varchar(255),
	address2    varchar(255),
	city	    varchar(255),
	state	    varchar(255),
	zip	    varchar(255),
	country	    varchar(255),
	phone	    varchar(255),
a47 2
	isbn	   integer,
	form	   varchar(255),
d62 1
a62 1
create tables fines (
a76 1

@
