Click to See Complete Forum and Search --> : SQL Queries


simpsons
11-29-2007, 12:51 PM
I'm having trouble with one query in particular. I have created five tables, and now I want to add some foreign keys to the tables. However when I add code for the constraints, an error message pops up. Due to this, I have used the 'Alter' command and then the 'Add' command as follows:

ALTER TABLE ViewingAppointment
ADD CONSTRAINT ViewingAppointment_AppointmentCode_pk PRIMARY KEY (AppointmentCode),
ADD CONSTRAINT ViewingAppointment_PotentialBuyerCode_fk FOREIGN KEY (PotentialBuyerCode) REFERENCES PotentialBuyer (PotentialBuyerCode),
ADD CONSTRAINT ViewingAppointment_HouseCode_fk FOREIGN KEY (HouseCode) REFERENCES SaleProperty (HouseCode),
ADD CONSTRAINT ViewingAppointment_StaffName_fk FOREIGN KEY (StaffName) REFERENCES StaffMember (StaffName));

An error message is still popping up, this time saying 'syntax error in field definition'. Any help would be appreciated.

Another thing I was wondering. I want to find out the number of properties that has been sold for each property type.
To do this would I need the GROUP BY command?

Thank you.

chazzy
11-29-2007, 01:15 PM
what database system are you using?

simpsons
11-29-2007, 01:29 PM
I'm using MS Access.

chazzy
11-30-2007, 05:30 AM
unfortunately (or fortunately?) I don't know much of access's syntax.

my guess is that you need to

Alter table .... Add constraint.... for each row, not one big block like you've done.

I did find this link, it seems to have the syntax for you.

http://www.blueclaw-db.com/alter_table_ddl.htm