create database customer
use customer
CREATE TABLE `customer`.`buyer` (
`id` VARCHAR(10) NOT NULL,
`name` VARCHAR(5) NOT NULL,
`jumin_no` CHAR(13) NULL,
`phone` CHAR(11) NOT NULL,
PRIMARY KEY (`id`));
insert into buyer values('abc123', 'choro', '9510211174061', '01021178112')
insert into buyer values('el426', 'elen', '9702112017120', '01049411772')
insert into buyer values('kwt486', 'keny', '0011111941875', '01071481417')
CREATE TABLE `customer`.`product` (
`product_no` INT NOT NULL,
`product_name` VARCHAR(20) NOT NULL,
`price` INT NOT NULL,
PRIMARY KEY (`product_no`));
insert into product values('10', '아크네스폼클랜져', '7900')
insert into product values('15', '케라시스샴푸', '6900')
insert into product values('20', '케라시스린스', '5900')
CREATE TABLE `customer`.`p_order` (
`order_no` INT NOT NULL,
`id` VARCHAR(10) NULL,
`order_date` CHAR(8) NOT NULL,
`product_no` INT NULL,
PRIMARY KEY (`order_no`),
INDEX `id_idx` (`id` ASC),
INDEX `product_no_idx` (`product_no` ASC),
CONSTRAINT `id`
FOREIGN KEY (`id`)
REFERENCES `customer`.`buyer` (`id`)
ON DELETE SET NULL
ON UPDATE SET NULL,
CONSTRAINT `product_no`
FOREIGN KEY (`product_no`)
REFERENCES `customer`.`product` (`product_no`)
ON DELETE SET NULL
ON UPDATE SET NULL);
insert into p_order values('1', 'abc123', '20181112', '1')
insert into p_order values('2', 'kwt486', '20181112', '2')
insert into p_order values('3', 'el426', '20181112', '3')
`p_order`위 테이블의 내용을 입력을 하려고하니 입력이 안됩니다 ㅜㅜmysql 1452 에러 뜨구요
p_order 테이블의 id와 product_no에 포린키를 설정하고싶습니다
포린키 설정했는데 뭐가 잘못됐는지 모르겠어요...
|