如何执行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...