如何在SQL Server的单个列中插入多个值(如数组) [英] How to insert multiple value(like an array)in a single column in SQL server
本文介绍了如何在SQL Server的单个列中插入多个值(如数组)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在sql server中存储多个值,我已经在Oracel中完成了这个但是在SQL服务器中我能够做到这一点请建议一些aleternate
我尝试了什么:
i已经厌倦了使用Declare,但它的存储时间不长
解决方案
你不能在一个单元格中存储一个数组,这是一个坏主意 - 你可以通过将数组的每个元素转换为字符串并将它们连接起来形成CSV数据来实现它,但那是一个噩梦,以后再使用。
如果你试图将一个数组存储到多行中,那就太糟糕了:将你的数组转换为DataTable并使用 SqlBulkCopy.WriteToServer方法(DataRow [])(System.Data.SqlClient) [ ^ ]
i want to store multiple value in sql server, i have done this in Oracel but it in SQL server i am able to do that please suggest some aleternate
What I have tried:
i have tired using Declare but it doesnt store value longer
解决方案
You can't store an array in a single cell and it would be a bad idea to try - you can do it by converting each element of the array to a string and concatenate them to form CSV data, but that's a nightmare to work with later.
If you are trying to store an array into multiple rows, that's not too bad at all: convert your array to a DataTable and use the SqlBulkCopy.WriteToServer Method (DataRow[]) (System.Data.SqlClient)[^]
这篇关于如何在SQL Server的单个列中插入多个值(如数组)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文