MySQL 查询插入默认数据而不是输入数据

标签 mysql insert auto-increment

我目前正在为私有(private)住房贷款部门编写一个网络应用程序。在此应用程序中,贷款条款是在借款人、发起人和资金来源之间创建的,以便他们在申请贷款时可以选择最符合其需求的条款...

我使用的是 MySQL 5.4。该表具有三个外键(borrowerId、originatorId、fundingSourceId)。可以更新现有行,但我的插入命令不会插入其数据,而只会插入具有表默认值的新行。表格的格式如下...

id                  int(11)    NOTNULL,PRIMARY,AUTO_INCREMENT
borrowerId          int(11)    NOTNULL,DEFAULT 0
originatorId        int(11)    NOTNULL,DEFAULT 0
fundingSourceId     int(11)    NOTNULL,DEFAULT 0
originatorFee       dec(10,2)  NOTNULL
fundingSourceFee    dec(10,2)  NOTNULL
interestRate        dec(5,3)   NOTNULL
penaltyRate         dec(5,3)   NOTNULL
loanDuration        int(11)    NOTNULL,DEFAULT 0
minimumInterestDays int(11)    NOTNULL,DEFAULT 0
disabled            tinyint(1) NOTNULL,DEFAULT 0
createdAt           datetime   NOTNULL
updatedAt           datetime   NULL
deletedAt           datetime   NULL

这是我的插入命令,它生成一行全为零的行,而不是我输入的数据(包括创建于 0000-00-00 00:00:00)

INSERT INTO loanterms
(borrowerId,originatorId,originatorFee,fundingSourceId,fundingSourceFee,
interestRate,penaltyRate,loanDuration,minimumInterestDays,disabled,createdAt)
VALUES (borrowerId = 64, originatorId = 3, originatorFee = 300.00, 
fundingSourceId = 11, fundingSourceFee = 300.00, interestRate = 15.00, 
penaltyRate = 20.00, loanDuration = 6, minimumInterestDays = 30, disabled = 0,
createdAt = now())

编辑:以下查询生成一行,其中正确包含所有数据...我必须将 ID 自动递增字段插入到查询中。这是不是说明我的自增有问题呢?我该如何修复它?

INSERT INTO loanterms VALUES (124, 64, 3, 11, 300.00, 300.00, 15.00, 20.00, 6, 
30, 0, now(), NULL, NULL)

编辑2:谢谢大家指出我的愚蠢错误...抱歉,我花了几分钟才意识到这一点。这是一个午夜查询,我今天还没有喝咖啡......

最佳答案

MySQL:

更改:

INSERT INTO loanterms
(borrowerId,originatorId,originatorFee,fundingSourceId,fundingSourceFee,
interestRate,penaltyRate,loanDuration,minimumInterestDays,disabled,createdAt)
VALUES (borrowerId = 64, originatorId = 3, originatorFee = 300.00, 
fundingSourceId = 11, fundingSourceFee = 300.00, interestRate = 15.00, 
penaltyRate = 20.00, loanDuration = 6, minimumInterestDays = 30, disabled = 0,
createdAt = now())

:

INSERT INTO loanterms
set borrowerId = 64, 
    originatorId = 3, 
    originatorFee = 300.00, 
    fundingSourceId = 11, 
    fundingSourceFee = 300.00, 
    interestRate = 15.00, 
    penaltyRate = 20.00, 
    loanDuration = 6, 
    minimumInterestDays = 30, 
    disabled = 0,
    createdAt = now();

关于MySQL 查询插入默认数据而不是输入数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23252555/

相关文章:

Java和MySQL插入语句

mysql - 在 MYSQL 中使用 AUTO_INCRMENT

mysql - 在 mysql 迁移到 postgres 后重新启动主键序列,最重要的是为参照完整性方面保留旧数据

postgresql - 将主键 int 类型更改为 serial

mysql - 将 SQL 代码转换为关系代数

php - 将另一个表中的行连接到另一个表中的行 php mysql

mysql - 导入大型数据库 - CPanel & MySQL & PHPMyAdmin

mysql - SQL 查询虽然构造正确,但返回 1064 错误

mysql - fork MySQL INSERT INTO (InnoDB)

php - SQL INSERT INTO 不起作用