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));

Recommended Answers

All 2 Replies

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.