Home » Other » Training & Certification » Foreign key problem (Oracle)
Foreign key problem [message #283258] Mon, 26 November 2007 09:31 Go to next message
Hunter_wow
Messages: 31
Registered: November 2007
Member
Hello. Working on a school assignment and got some problem with creating my first tables. Oracle returns a error for the table "Student" who should contain the keys of both Program and Branch(weak). Have also tried to type "FOREIGN KEY(ProgramName) REFERENCES Program(Name));)," right after StudentName VARCHAR(50), but this also gives error. Any hint on how the FOREIGN KEY for progam should look? The Program table and Branch table seems to be correct.

CREATE TABLE Program(
Name VARCHAR(50), 
Abbreviation VARCHAR(10), 
PRIMARY KEY(Name));

CREATE TABLE Branch(
Abbreviation VARCHAR(10),
ProgramName VARCHAR(50) REFERENCES Program(Name),
PRIMARY KEY(ProgramName,Abbreviation));

CREATE TABLE Student(
ID INT, 
StudentName VARCHAR(50),
ProgramName VARCHAR(50),
BranchAbbreviation VARCHAR(10) REFERENCES Branch(Abbreviation),
PRIMARY KEY(ID),
FOREIGN KEY(ProgramName) REFERENCES Program(Name));
Re: Foreign key problem [message #283260 is a reply to message #283258] Mon, 26 November 2007 09:36 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
The SQL Reference Manual can be found at http://tahiti.oracle.com
http://asktom.oracle.com contains many fine coding examples..
Re: Foreign key problem [message #283264 is a reply to message #283258] Mon, 26 November 2007 09:47 Go to previous messageGo to next message
Hunter_wow
Messages: 31
Registered: November 2007
Member
Ah, great. Thanks a lot Wink
Re: Foreign key problem [message #283287 is a reply to message #283264] Mon, 26 November 2007 10:42 Go to previous message
Michel Cadot
Messages: 68728
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
In addition, don't use VARCHAR, use VARCHAR2 datatype.

Regards
Michel
Previous Topic: Request For a Query
Next Topic: how to write a procedure for following query
Goto Forum:
  


Current Time: Sat Dec 28 13:36:00 CST 2024