SQL插入查询 [英] SQL Insert Query

查看:95
本文介绍了SQL插入查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设在数据库中有两个表,名称分别为emp1和emp2,并且这些字段位于emp1(emp_id,emp_name)和emp2(emp_address,emp_sal)中.现在如何在同一个sql插入查询中将emp1和emp2中的所有值插入?

Suppose there is two table in a database named like emp1 and emp2 and the fields are in emp1(emp_id,emp_name) and in emp2(emp_address,emp_sal). Now how can I insert all the value in emp1 and emp2 in a same sql insert query?

推荐答案

是否有充分的理由将这些值保留在单独的表中? br/>
还是您没有听说过数据库规范化 [
Is there a good reason to keep these values in separate tables?

Or haven''t you heard about Database Normalization[^]?


您不能通过单个SQL查询将其插入到两个表中.

如果需要,您可以尝试使用存储过程,其中调用一个过程将完成此工作(一个SP可以有多个查询).
参考:
MSDN:HOW TO:使用Visual C#.NET在ASP.NET中调用SQL Server存储过程 [ ADO.NET:使用存储过程 [ MSDN:创建过程(Transact-SQL) [
You cannot insert into two tables from a single SQL query.

If needed, you can try using Stored Procedure where calling one procedure will do the job (one SP can have multiple queries).
Refer:
MSDN: HOW TO: Call SQL Server Stored Procedures in ASP.NET by Using Visual C# .NET[^]
ADO.NET : Using Stored Procedures[^]
MSDN: CREATE PROCEDURE (Transact-SQL)[^]


我认为这是不可能的.您要使用两个插入查询或将所有记录保留在一个表中
I think it not possible. You want to use two insert query or keep all records in one table


这篇关于SQL插入查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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