I have a problem to add a Foreign key to a table. I have tried
ALTER TABLE Child
ADD FOREIGN KEY (pc_id)
REFERENCES Parent_Carer(pc_id);
, but it does not add the key. The structure:
CREATE TABLE Parent_Carer (
pc_id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
pc_title CHAR(5) NOT NULL,
pc_fname VARCHAR(15) NOT NULL,
pc_lname VARCHAR(20) NOT NULL,
pc_phone VARCHAR(15) NOT NULL,
pc_address1 VARCHAR(25) NOT NULL,
pc_address2 VAR开发者_如何学运维CHAR(25) NOT NULL,
pc_town VARCHAR(35) NOT NULL,
pc_postcode VARCHAR(15) NOT NULL) ;
CREATE TABLE Child(
child_id INT AUTO_INCREMENT PRIMARY KEY NOT NULL,
pc_id INT NOT NULL,
child_fname VARCHAR(20) NOT NULL,
child_lname VARCHAR(20) NOT NULL,
child_dob DATE NOT NULL,
child_gender ENUM ('F','M') DEFAULT 'F' NOT NULL);
Thank you.
What are you using to display the Foreign Key? You need to use one of the following:
SHOW CREATE TABLE tbl_name;
or
SHOW TABLE STATUS FROM db_name LIKE 'tbl_name';
Reference
精彩评论