Received: from Donald.bks ([203.145.133.16]) by postgresql.org (8.11.3/8.11.4) with ESMTP id f7ABK8P65085 for ; Fri, 10 Aug 2001 07:20:11 -0400 (EDT) (envelope-from bhuvansql@yahoo.com) Received: from Larry.bks (root@Larry.bks [200.2.1.10]) by Donald.bks (8.11.2/8.11.2) with ESMTP id f7ABIPG05632; Fri, 10 Aug 2001 16:48:29 +0530 Received: from localhost (bhuvan@localhost) by Larry.bks (8.9.3/8.8.5) with ESMTP id QAA06576; Fri, 10 Aug 2001 16:47:18 +0530 X-Authentication-Warning: Larry.bks: bhuvan owned process doing -bs Date: Fri, 10 Aug 2001 16:47:18 +0530 (IST) From: Bhuvan A X-Sender: bhuvan@Larry.bks To: Johny Jugianto cc: pgsql-sql@postgresql.org Subject: Re: INSERT FOLLOW WITH OTHER INSERT In-Reply-To: <20010810034316.2823.qmail@web14603.mail.yahoo.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Archive-Number: 200108/143 X-Sequence-Number: 4364 Are you ready to solve your problem using a trigger and 'plpgsql' function ?? .. then proceed .. trigger :) +++++++++++++++++++++++++++++++++++++++++++ CREATE TRIGGER trigger_student_club before INSERT OR UPDATE ON students FOR EACH ROW EXECUTE PROCEDURE ins_student_club_func(); +++++++++++++++++++++++++++++++++++++++++++ function :) +++++++++++++++++++++++++++++++++++++++++++ CREATE FUNCTION ins_student_club_func() RETURNS OPAQUE AS 'BEGIN INSERT INTO student_club(student_id) VALUES (new.student_id); return new; END;' LANGUAGE 'plpgsql'; +++++++++++++++++++++++++++++++++++++++++++ Hope it works. :) Regards, Bhuvaneswar. On Aug 9, Johny Jugianto wrote: > hi all > > i have a table like this > > CREATE SEQUENCE seq_student_id INCREMENT 1 START 1; > CREATE TABLE students ( > student_id INT4 NOT NULL DEFAULT > NEXTVAL('seq_student_id'), > student_name text, > student_address text, > primary key(student_id) > ) > CREATE TABLE student_club ( > student_id INT4 NOT NULL; > club_id INT4, > CONSTRAINT student_id_update FOREIGN KEY(student_id) > REFERENCES students(student_id) ON UPDATE CASCADE > ) > > my question is how i can make auto insert student_id > on table student_club when i insert into table > students > > example: > INSERT INTO students(student_name) VALUES('Willy'); > > table STUDENT > student_id | name | address > --------------------------------- > 1 | Willy | > > and on TABLE student_club > student_id | club_id > -------------------- > 1 | > > > i have trying with create rule and with > check_foreign_key, but i haven't found solution. > anyone can help me? > > Thanks in advance > > > __________________________________________________ > Do You Yahoo!? > Make international calls for as low as $.04/minute with Yahoo! Messenger > http://phonecard.yahoo.com/ > > ---------------------------(end of broadcast)--------------------------- > TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org >