如何执行sql查询“使用单个查询插入多个表”... [英] How Perform sql query "Insert in to Multiple table using single query"...

查看:101
本文介绍了如何执行sql查询“使用单个查询插入多个表”...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I am Trying this query but not perform..

INSERT INTO student,address(student.c_name,address.city) values ('moin','nadiad')

In this query student and address are table and 'moin','nadiad' are column data..

推荐答案

不可能!!!

不能一次在两个表中插入值。 。

你尝试双插入查询更好..
impossible !!!
can not insert values in two table at a time..
better you try double insert query..


你不能在一个语句中对两个表使用INSERT。

我建议在这里使用交易。例如:



You can't use INSERT against two tables in one statement.
I would suggest to use transaction here. For example :

SET XACT_ABORT ON
BEGIN TRANSACTION

INSERT INTO [A](...) VALUES(...);
INSERT INTO [B](...) VALUES(...);

COMMIT TRANSACTION
SET XACT_ABORT OFF


为什么需要这种类型的查询。您可以通过以下方式执行此操作: -



插入学生(c_name)值('moin')



插入地址(城市)值('nadiad')



希望,这会对你有帮助......
Why do you need such type of query. You can perform this by simple using this:-

Insert into student (c_name) values ('moin')

Insert into address (city) values ('nadiad')

Hope, this will helps you...


这篇关于如何执行sql查询“使用单个查询插入多个表”...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆