从C#数据表创建SQL Server表 [英] Creating a SQL Server table from a C# datatable

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

问题描述

我有我手动创建和使用C#加载数据的数据表。

I have a DataTable that I manually created and loaded with data using C#.

什么是最有效的方式来创建一个使用的列和数据在数据表中的SQL Server 2005中的表?

What would be the most efficient way to create a table in SQL Server 2005 that uses the columns and data in the DataTable?

推荐答案

这是一个有点不寻常的SQL创建表了一个DataTable对象的客户端提供的定义。表是精心打造的实体SQL,与部署时考虑的位置在设计时选择合适的磁盘,用分度考虑,并与所有参与适当的模型数据库中的问题。

It's a little bit unusual in SQL to create tables out of a client supplied definition of a Datatable object. Tables are carefully crafted entities in SQL, with deploy time placement consideration of choosing the proper disk, with indexing consideration at design time and with all the issues involved in properly modeling a database.

更好的你解释一下你想实现让我们明白什么建议给什么。

Better you'd explain what you're trying to achieve so we understand what advice to give.

作为一个侧面说明,在SQL 2008年有一个很简单的方法来创建一个表出来定义DataTable中的一个客户端:通过数据表为表值参数,然后发出 SELECT * I​​NTO&LT ;表名>从@tvp ,这将有效的数据表中的的内容数据的定义转化为一个真正的表中的SQL。

As a side note, in SQL 2008 there is a very easy way to create a table out of a client defined Datatable: pass the DataTable as a Table value parameter, then issue a SELECT * INTO <tablename> FROM @tvp, this will effectively transfer the definition of the Datatable and its content data into a real table in SQL.

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

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