gpt4 book ai didi

mysql - 尝试更改表约束时出现错误代码 1452

转载 作者:行者123 更新时间:2023-11-29 10:35:53 25 4
gpt4 key购买 nike

ALTER TABLE `charter`
ADD CONSTRAINT `charter_ibfk_3` FOREIGN KEY (`CHAR_DESTINATION`)
REFERENCES `airport` (`AIRPORT_CODE`);

我正在尝试建立这种关系:

enter image description here

Charter and Airport ERD Diagram

CREATE TABLE `antonellacammarota` (
`CUS_CODE` int(6) NOT NULL DEFAULT '0',
PRIMARY KEY (`CUS_CODE`),
FOREIGN KEY (`CUS_CODE`) REFERENCES `CUSTOMER` (`CUS_CODE`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

insert into customer values (10076, "Cammarota", "Antonella", "T", "805", "555-1212", 0);

insert into antonellacammarota(select cus_code from customer where cus_lname = 'Cammarota');

--
-- Table structure for table `airport`
--

CREATE TABLE IF NOT EXISTS `airport` (
`AIRPORT_CODE` varchar(3) NOT NULL DEFAULT '0',
`AIRPORT_NAME` varchar(40) DEFAULT NULL,
`AIRPORT_ADDRESS` varchar(45) DEFAULT NULL,
`AIRPORT_CITY` varchar(25) DEFAULT NULL,
`AIRPORT_STATE` char(2) DEFAULT NULL,
`AIRPORT_ZIP` varchar(10) DEFAULT NULL,
`AIRPORT_COUNTRY` varchar(25) DEFAULT NULL,
`AIRPORT_AREACODE` varchar(3) DEFAULT NULL,
`AIRPORT_PHONE` varchar(8) DEFAULT NULL,
PRIMARY KEY (`AIRPORT_CODE`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Constraints for table `airport`
--
ALTER TABLE `charter`
ADD CONSTRAINT `charter_ibfk_3` FOREIGN KEY (`CHAR_DESTINATION`) REFERENCES `airport` (`AIRPORT_CODE`);


--
-- Dumping data for table `airport`
--

INSERT INTO `airport` (`AIRPORT_CODE`, `AIRPORT_NAME`, `AIRPORT_ADDRESS`, `AIRPORT_CITY`, `AIRPORT_STATE`,
`AIRPORT_ZIP`, `AIRPORT_COUNTRY`, `AIRPORT_AREACODE`, `AIRPORT_PHONE`) VALUES
('ATL', 'Hartsfield-Jackson Atlanta Int', '6000 N Terminal Pkwy.', 'Atlanta', 'GA', '30320', 'US', '808', '897-1910'),
('BNA', 'Nashville Int', '1 Terminal Dr.', 'Nashville', 'TN', '37214', 'US', '615', '275-1675'),
('GNV', 'Gainesville Regional', '3880 NE 39th Ave.', 'Gainesville', 'FL', '32609', 'US', '352', '373-0249'),
('MOB', 'Mobile Regional', '8400 Airport Blvd.', 'Mobile', 'AL', '36608', 'US', '800', '357-5373'),
('MOY', 'Monterrey', '', 'Monterrey', '', '', 'Columbia', '', ''),
('STL', 'St. Louis Lambert Int', '10701 Lambert International Blvd.', 'St. Louis', 'MO', '63145', 'US', '314', '426-8000'),
('TYS', 'McGhee Tyson', '2055 Alcoa Hwy', 'Alcoa', 'TN', '37701', 'US', '865', '345-3000');

最佳答案

用它来找出哪个条目把事情搞砸了

SELECT CHAR_TRIP, CHAR_DESTINATION 
FROM charter
WHERE CHAR_DESTINATION NOT IN (
SELECT AIRPORT_CODE FROM airport);

关于mysql - 尝试更改表约束时出现错误代码 1452,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46431972/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com