0

Just struggling through my SQL coursework, and already fallen over the first stubling block :(

My case study tells me that i need to put a foreign key from my centre table (parent) to my salesman table (child) on a 1-1 relationship.

Trying to add my foreign key, which is where my problems begin. The centre (parent) table compiles and runs fine. And when i dont use the foreign key, so does salesman. But when i put the foreign key in, it complains, telling me "could not find field".

Now i have looked around, and read that the lack of data in centre is the cause of this. So i have populated the table with some data and tried again, yet it doesnt work. So, can anyone shead light on what im not doing right.

Much appretiated

//Centre code (parent table)
CREATE TABLE Centre
(CentreNo VARCHAR (8) NOT NULL,
Location VARCHAR (15) NOT NULL,
County VARCHAR (15) NOT NULL,
Telephone VARCHAR (11) NOT NULL,
CONSTRAINT Centre_CentreNo_pk PRIMARY KEY (CentreNo));
//Salesman code (child table)
CREATE TABLE Salesperson
(SalespersonNo VARCHAR (8) NOT NULL,
FullName VARCHAR (15) NOT NULL,
Commision CURRENCY,
CONSTRAINT CentreNo_fk FOREIGN KEY (CentreNo) REFERENCES Centre(CentreNo),
CONSTRAINT SalespersonNo_pk PRIMARY KEY (SalespersonNo));
2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by Suicidal_tool
1

Hi,

Could you give a try like this way;

//Salesman code (child TABLE)
CREATE TABLE Salesperson
(SalespersonNo VARCHAR (8) NOT NULL,
FullName VARCHAR (15) NOT NULL,
Commision Decimal,
CentreNo VARCHAR (8) CONSTRAINT CentreNo_fk FOREIGN KEY (CentreNo) REFERENCES Centre(CentreNo),
CONSTRAINT SalespersonNo_pk PRIMARY KEY (SalespersonNo));

Let me know if this helps.

Good luck.

0

Thats the simple thing i missed.....Much appretiated

Hi,

Could you give a try like this way;

//Salesman code (child TABLE)
CREATE TABLE Salesperson
(SalespersonNo VARCHAR (8) NOT NULL,
FullName VARCHAR (15) NOT NULL,
Commision Decimal,
CentreNo VARCHAR (8) CONSTRAINT CentreNo_fk FOREIGN KEY (CentreNo) REFERENCES Centre(CentreNo),
CONSTRAINT SalespersonNo_pk PRIMARY KEY (SalespersonNo));

Let me know if this helps.

Good luck.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.