我有这三张桌子 贷款, 顾客, loans_customers
贷款有一个记录insert into loans values(1234, "st", '2015-01-11', 2000);
客户有一条记录
insert into customers values(2276, "Anay", "Student");
我创建了另一个表loan_customers
create table loans_customers(
loans_customers_id decimal(10),
primary key(loans_customers_id),
loan_id decimal,
customer_id decimal,
constraint FK_loans foreign key(loan_id) references loans(loan_id),
constraint FK_customers foreign key(customer_id) references customers(customer_id));
现在我正在尝试插入值
insert into loans_customers values(3376, ?, ?);
在上面的语法中,如何在?,?的位置给出值,以便它可以完美地存在多对多的关系。
谢谢,
答案 0 :(得分:2)
首先,在使用insert
时,您应该始终列出列。然后,你只需要包含id:
insert into loans_customers(loans_customers_id, loan_id, customer_id)
values(3376, 1234, 2276);
如果您使用带参数的预准备查询,则可以使用参数提供值。