使用单个查询在多个表中插入数据
INSERT INTO client_1.student_info, client_1.admission_details,client_1.parent_info,client_1.student_grade_mapping,client_1.parent_student_mapping(
year1, division, id, student_id, firstname, lastname, gender, admissionno, student_id, admissiondate, tc_date, tc_issue_date,
student_photo, dob, is_delete,student_id, parent_id, father_name, father_age, father_education,
father_occupation, father_ph_no, father_ph_enabled, fatheremail,
creation, mother_name, mother_age, mother_education, mother_occupation,
mother_ph_no, mother_ph_enabled, motheremail, religion, address,
state, city, zipcode,sg_id, student_id, grade_id,ps_id, parent_id, student_id)
VALUES (?, ?, ?, ?, ?, ?, ?,
?, ?, ?,?, ?, ?, ?, ?,?, ?, ?, ?, ?,
?, ?, ?, ?,
?, ?, ?, ?, ?,
?, ?, ?, ?, ?,
?, ?, ?,?, ?, ?,?, ?, ?);
答案 0 :(得分:0)
您无法使用单个查询将数据插入多个表中。您必须使用存储过程或在事务中包装两个查询。
答案 1 :(得分:0)
joel-coehoorn已经提到了here
在一个声明中:这是不可能的
但在一个交易中:可能
BEGIN TRANSACTION
DECLARE @DataID int;
INSERT INTO DataTable (Column1 ...) VALUES (....);
INSERT INTO LinkTable (Column1 ...) VALUES (....);
COMMIT
答案 2 :(得分:0)
答案实际上取决于数据库。就像其他人说的那样(很多人已经在StackOverflow上回答过),你需要一个交易或存储过程;但是,如果您使用的是Oracle 9i,那么您就可以开展业务(http://www.oracle-developer.net/display.php?id=209)。
快乐狩猎。