将数据插入SQL表 [英] Insert Data into SQL Table

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

问题描述

我的数据表中的数据就像

The Data in my DataTable is like

ID ContactName1  Designation1 ContactName2 Designation2
1  A             dummy        B            sam 

我的表的表结构是

ID ContactName Designation

我将存储过程中的值传递为:

I am passing the values in the stored procedure as:

@ContactName1
@Designation1

@ContactName2
@Designation2

我想要一个插入语句来插入记录.

I want a single insert statement to insert the records.

我该如何实现?

推荐答案

假定ID主键设置为自动递增,并且表具有三个字段:

Assuming your ID primary key is set on auto-increment, and your table has three fields:

INSERT INTO DataTable (ContactName, Designation) VALUES 
    (@ContactName1, @Designation1), 
    (@ContactName2, @Designation2);

根据实际ID,如果您没有自动递增的ID(根据对Ivan响应的评论判断,则不是),您实际上可以使用MAX()语句获取它:

As per the actual ID, if you don't have it on auto-increment, which judging from the comment on Ivan's response, you don't, you could actually get it using the MAX() statement:

SELECT MAX(ID) AS max_id FROM DataTable

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

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