Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL More than 1 foreign key

Status
Not open for further replies.

B0ssa

Technical User
Dec 5, 2004
3
GB
Somebody please help this is driving me up the wall I need to make a database using sql heres what the table looks like in SQL

Create Table VolcanicActivityHazard
(VolcanoName TEXT(20)NOT NULL,
ActivityStartDate DATE NOT NULL,
Hazard TEXT(25) NOT NULL,
NoOfFatalities NUMBER,
Indicator TEXT(1),
Constraint PKIndex PRIMARY KEY ([VolcanoName],[ActivityStartDate],[Hazard]),
CONSTRAINT FKVolcanoNameone FOREIGN KEY ([VolcanoName]) REFERENCES Volcano);

Im trying to add a second foreign key but it keeps giving me errors the foreign key is called ACTIVITY START DATE and it's from a table called Volcanic Activity, how would I write it into that database. I have tryed everything but Im still learning so I just cant figure it out.
 
It says relationship must be on the same number of fields with the same data types. This is for my college its the first time I have used SQL and it's drivcing me up the wall.
 
Code:
alter table VolcanicActivityHazard
add
CONSTRAINT FKActivity 
FOREIGN KEY (VolcanoName,ActivityStartDate) 
REFERENCES VolcanicActivity

If you have this foreign key you shouldn't need the first one.
 
Thanks guys I was at that till 2:30 am last night trying to get it working.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top