Friday, April 20, 2012

parent and child table foreign key

I currently have a parent table:



CREATE TABLE members (
member_id SERIAL NOT NULL, UNIQUE, PRIMARY KEY
first_name varchar(20)
last_name varchar(20)
address address (compsitie type)
contact_numbers varchar(11)[3]
date_joined date
type varchar(5)
);

CREATE TABLE basic_member (
activites varchar[3]) // can only have 3 max activites
INHERITS (members)
);

CREATE TABLE full_member (
activities varchar[]) // can 0 to many activities
INHERITS (members)
);


I also have another table called



CREATE TABLE planner (
day varchar(9) FOREIGN KEY REFERENCES days(day)
time varchar(5) FOREIGN KEY REFERENCES times(time)
activity varchar(20) FOREIGN KEY REFERENCES activities(activity)
member bigint FOREIGN KEY REFERENCES members(member_id)

ALTER TABLE planner ADD CONSTRAINT pk_planner PRIMARKY KEY (day,time,activity,member);


I am currently trying to add with



INSERT INTO planner VALUES ('monday','09:00','Weights',2);


I have added a set into full_members with



INSERT INTO full_members 
VALUES (Default, 'Hayley', 'Sargent', (12 Forest Road','Mansfield','Nottinghamshire','NG219DX'),'{01623485764,07789485763,01645586754}',20120418,'Full');


My insert is currently not working





No comments:

Post a Comment