X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 4C169D1B956 for ; Tue, 23 Sep 2003 20:31:29 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 44606-08 for ; Tue, 23 Sep 2003 17:31:20 -0300 (ADT) Received: from news.hub.org (unknown [64.117.224.194]) by svr1.postgresql.org (Postfix) with ESMTP id 9ADBFD1B58D for ; Tue, 23 Sep 2003 17:31:18 -0300 (ADT) Received: from news.hub.org (host-64-117-224-194.altec1.com [64.117.224.194] (may be forged)) by news.hub.org (8.12.9/8.12.9) with ESMTP id h8NKVHhK077519 for ; Tue, 23 Sep 2003 20:31:17 GMT (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.12.9/8.12.9/Submit) id h8NKKnJa076045 for pgsql-admin@postgresql.org; Tue, 23 Sep 2003 20:20:49 GMT From: "Mark Carew" X-Newsgroups: comp.databases.postgresql.admin Subject: Re: steps to ensure referential integrity Date: Wed, 24 Sep 2003 06:20:52 +1000 Organization: Hub.Org Networking Services Lines: 107 Message-ID: References: <3F6F18F7.4000400@virginia.edu> X-Complaints-To: usenet@news.hub.org X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 To: pgsql-admin@postgresql.org X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200309/366 X-Sequence-Number: 10454 ________________________________ Hi Jodie, This snippet is generated code from my client side data dictionary for postgresql. The sequence described is used with nextval() to obtain autoincrement key values for the primary key. Thus primary key definition does create an index as do foreign key declarations. I use the views to mimic conditional indices. Each view has a companion index generated if one suitable is not already in existance. HTH Mark Carew Brisbane Australia 07 35117911 /* client side */ IF ascan(aTokens,"AUTOINC") > 0 * ::AutoInc := TRUE * IF cColumnType == "CS" * #IFDEF SQLFILES * ::SqlDefault := ; "SELECT nextVal('" + ; lower(::oTable:filename) + ; "_seq') ;" * #ENDIF * ENDIF * ENDIF /* server side */ DROP SEQUENCE invhdr_seq ; CREATE SEQUENCE invhdr_seq START 322 ; DROP TABLE invhdr ; CREATE TABLE invhdr ( vinno int4, vindate date NOT NULL, dateent date, clientno char(12) NOT NULL, total numeric(10,2), balance numeric(10,2), allocamt numeric(10,2), gst numeric(9,2), cordno char(14), printed char(1) , origin char(1) , PRIMARY KEY ( vinno ) ,FOREIGN KEY (clientno ) REFERENCES client ON UPDATE RESTRICT ON DELETE RESTRICT ); CREATE INDEX invhdr_dateclt ON invhdr (vindate, clientno); CREATE INDEX invhdr_vindate ON invhdr (vindate); CREATE INDEX invhdr_dateent ON invhdr (dateent); DROP VIEW invhdr_unprint_view ; CREATE VIEW invhdr_unprint_view AS SELECT * FROM invhdr WHERE PRINTED = 'N' ORDER BY vinno ; CREATE INDEX invhdr_clntactv ON invhdr (clientno, vindate); DROP VIEW invhdr_clntactv_view ; CREATE VIEW invhdr_clntactv_view AS SELECT * FROM invhdr WHERE BALANCE <> cast( 0.00 as numeric ) ORDER BY clientno, vindate ; CREATE INDEX invhdr_cordno ON invhdr (cordno); DROP VIEW invhdr_cordno_view ; CREATE VIEW invhdr_cordno_view AS SELECT * FROM invhdr WHERE CORDNO <> ' ' ORDER BY cordno ;