sqlbulkcopy

Select into statement where source is other database

余生颓废 提交于 2019-12-01 16:25:31
问题 How to copy data from one DB into another DB with the same table structure and keep the key identities? I use Sql Server 2012 "Denali" and I want to copy some data from a Sql Server 2008 DB. The tables I have are exactly the same but I want the data from the old DB into the new "Denali" DB. The databases are on different servers. So I want something like USE newDB; GO SELECT * INTO newTable FROM OldDb.oldTable WITH (KEEPIDENTITY); GO Anyone have a suggestion to make this workable ? 回答1:

How to get the Identity values in SQL BULK COPY?

怎甘沉沦 提交于 2019-12-01 13:30:21
I have to get the IDENTITY values from a table after SQLBULKCOPY to the same table. The volume of data could be thousands of records. Can someone help me out on this ? Disclaimer : I'm the owner of the project Bulk Operations In short, this project overcomes SqlBulkCopy limitations by adding MUST-HAVE features like outputting inserted identity value. Under the hood, it uses SqlBulkCopy and a similar method as @Mr Moose answer. var bulk = new BulkOperation(connection) // Output Identity Value bulk.ColumnMappings.Add("CustomerID", ColumnMappingDirectionType.Output); // Map Column bulk

Using SqlBulkCopy with F# to export matrix in SQL

匆匆过客 提交于 2019-12-01 10:44:55
I want to transfer a large amount of data from F# to an SQL table. Basically my F# code creates a matrix of three columns ( UserID, ProductID and price ) and N lines. I would like to "copy/pate it" into a database I tried several options but at the end, the transfer of data from F# is really slow (around one hour for 10000 lines). Thanks to answers of a previous question How to include a stored procedure in F# , an interesting way to resolve this problem is to use SqlBulkCopy . SqlBulkCopy requires a database type for its WritetoServer method but I didn't find any existing code or simple way

How to get the Identity values in SQL BULK COPY?

爷,独闯天下 提交于 2019-12-01 10:36:32
问题 I have to get the IDENTITY values from a table after SQLBULKCOPY to the same table. The volume of data could be thousands of records. Can someone help me out on this ? 回答1: Disclaimer : I'm the owner of the project Bulk Operations In short, this project overcomes SqlBulkCopy limitations by adding MUST-HAVE features like outputting inserted identity value. Under the hood, it uses SqlBulkCopy and a similar method as @Mr Moose answer. var bulk = new BulkOperation(connection) // Output Identity

How do I read a large file from disk to database without running out of memory

不想你离开。 提交于 2019-12-01 09:34:25
I feel embarrassed to ask this question as I feel like I should already know. However, given I don't....I want to know how to read large files from disk to a database without getting an OutOfMemory exception. Specifically, I need to load CSV (or really tab delimited files). I am experimenting with CSVReader and specifically this code sample but I'm sure I'm doing it wrong. Some of their other coding samples show how you can read streaming files of any size, which is pretty much what I want (only I need to read from disk), but I don't know what type of IDataReader I could create to allow this.

Using SqlBulkCopy with F# to export matrix in SQL

被刻印的时光 ゝ 提交于 2019-12-01 08:03:20
问题 I want to transfer a large amount of data from F# to an SQL table. Basically my F# code creates a matrix of three columns ( UserID, ProductID and price ) and N lines. I would like to "copy/pate it" into a database I tried several options but at the end, the transfer of data from F# is really slow (around one hour for 10000 lines). Thanks to answers of a previous question How to include a stored procedure in F#, an interesting way to resolve this problem is to use SqlBulkCopy . SqlBulkCopy

SqlBulkCopy cannot access table

自古美人都是妖i 提交于 2019-12-01 03:11:43
After reading in an excel-sheet (to transferTable), I want to add that data to a new table (destinationTable) using SqlBulkCopy, but I'm getting the error: Cannot access destination table 'test' I've tried using the default tablename and using square brackets, but that didn't work. Any suggestions? private void writeToDBButton_Click(object sender, EventArgs e) { MakeTable(); destinationTable.TableName = "test"; testDBDataSet.Tables.Add("test"); // Connects to the sql-server using Connection.cs SqlConnection connection = Connection.GetConnection(); using (connection) { connection.Open(); //

SqlBulkCopy cannot access table

六眼飞鱼酱① 提交于 2019-11-30 22:15:24
问题 After reading in an excel-sheet (to transferTable), I want to add that data to a new table (destinationTable) using SqlBulkCopy, but I'm getting the error: Cannot access destination table 'test' I've tried using the default tablename and using square brackets, but that didn't work. Any suggestions? private void writeToDBButton_Click(object sender, EventArgs e) { MakeTable(); destinationTable.TableName = "test"; testDBDataSet.Tables.Add("test"); // Connects to the sql-server using Connection

Get the count of rows from a COPY command

与世无争的帅哥 提交于 2019-11-30 20:39:10
When copying data from a file, you get the count of rows in psql with the "command tag": db=# COPY t FROM '/var/lib/postgres/test.sql'; COPY 10 I need the number of rows and would like to avoid a redundant count() on the table. Is there a way to get this count from COPY directly in a PL/pgSQL function? As far as I know there is none, but maybe I am missing something? For PostgreSQL 9.2. But any option in any version would be of interest. Not in PG 9.2, but there is in PG 9.3 courtesy of Pavel (E 1.3.1.7): Allow PL/pgSQL to access the number of rows processed by COPY (Pavel Stehule) The command

How does SqlBulkCopy Work

[亡魂溺海] 提交于 2019-11-30 18:43:42
I am familiar with the C# SqlBulkCopy class where you can call the 'WriteToServer' method passing through a DataTable. My question is what underlying mechanism in SQL server is used to bulk insert that data? The reason I ask is that the bulk insert referenced in the Bulk Insert MSDN T-SQL help file requires a data file to import. Does the SqlBulkCopy create a data file? I would like to understand this stuff to work out whether I can use the bulk insert functionality in SQL. If I write a SQL statement that prepares all the rows to insert into a particular table (thousands of rows) can I bulk