0

我有两个表,其字段如下所示:-

tbl_emp --> id(auto generate, auto increment, primary key),name, dob tbl_login --> id(指tbl_emp中的id, primary key), password

我有一个读取姓名、密码和出生日期(dob)的网络表单,以及一个提交按钮。在按下提交按钮时,数据被插入到第一个表中,也插入到第二个表中。如果我有办法从第一个表中访问“id”字段,那么将数据插入到第二列会很容易。

我的查询是:-

insert into tbl_emp (name,dob) values(@name, @dob);
insert into tbl_login (id,password) values((select id from tbl_emp where id=(select id from tbl_emp where id=id)), @password)

我遇到上述 coeds 的问题是:

Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
The statement has been terminated.
4

1 回答 1

0

您可以使用以下SCOPE_IDENTIY功能:

insert into tbl_emp (name,dob) values(@name, @dob);

insert into tbl_login (id,password) 
select id, @password 
from   tbl_emp 
where  id = SCOPE_IDENTITY();
于 2013-08-17T02:42:08.297 回答