mysql - MySQL插入失败
问题描述
我正在尝试在 sqlfiddle 上创建并插入 2 个表。
CREATE TABLE IF NOT EXISTS `Submissions` (
`sub_id` int(6) unsigned NOT NULL,
`hacker_id` int(3) unsigned NOT NULL,
`score` int(3) NOT NULL,
`sub_date` Date NOT NULL,
PRIMARY KEY (`sub_id`,`hacker_id`)
) DEFAULT CHARSET=utf8;
INSERT INTO `Submissions` (`sub_id`, `hacker_id`, `score`, `sub_date`) VALUES
('18833', '962', '12', '2019-12-07'),
('35892', '962', '45', '2019-12-07');
CREATE TABLE IF NOT EXISTS `Hacker` (
`hacker_id` int(10) NOT NULL,
`name` varchar(20) NOT NULL,
PRIMARY KEY(`hacker_id`, `name`)
)
INSERT INTO `Hacker` (`hacker_id`, `name`) VALUES
('123','Bob');
插入提交工作正常。我不明白我的 Insert into Hacker 有什么问题,失败了。
小提琴在这里:http ://sqlfiddle.com/#!9/d4d786但刷新会删除第二个插入,我猜是因为它无法编译/构建/无论 SQL 中的术语是什么。
解决方案
;
您在第二个CREATE TABLE
陈述之后缺少一个。它应该如下所示:
CREATE TABLE IF NOT EXISTS `Submissions` (
`sub_id` int(6) unsigned NOT NULL,
`hacker_id` int(3) unsigned NOT NULL,
`score` int(3) NOT NULL,
`sub_date` Date NOT NULL,
PRIMARY KEY (`sub_id`,`hacker_id`)
) DEFAULT CHARSET=utf8;
INSERT INTO `Submissions` (`sub_id`, `hacker_id`, `score`, `sub_date`) VALUES
('18833', '962', '12', '2019-12-07'),
('35892', '962', '45', '2019-12-07');
CREATE TABLE IF NOT EXISTS `Hacker` (
`hacker_id` int(10) NOT NULL,
`name` varchar(20) NOT NULL,
PRIMARY KEY(`hacker_id`, `name`)
);
INSERT INTO `Hacker` (`hacker_id`, `name`) VALUES
('123','Bob');
推荐阅读
- c# - 运动取决于帧速率。我怎样才能让它独立于帧速率
- reactjs - 警告:签名和功能的功能可能无法正常运行,因为其权利使用占位符团队 ID
- javascript - jquery关于表单计算最大值而不提交
- python - 使用 selenium 和 python 进行 YouTube 自动化,从搜索的视频中选择的问题
- python - 如何使用 Spyder 和 Python 2.7 安装 conda 环境?
- java - 在春季批处理中调用 Joblauncher.run 时获取空指针
- amazon-web-services - CW 警报维度中的参考实例 ID - Terraform
- javascript - 如何使用 React useContext 使子组件可以访问数据
- k-means - 使用 word2vec 进行文档聚类
- c# - 如何调用 Environment.GetEnvironmentVariable 而不会丢失 %PathVariableName% 例如 %SystemRoot%