Insert large amount of data into sql server

Asked

Viewed 1,045 times

1

I downloaded a list of cities on the internet. There are more than 5,000 municipalities. I tried a simple Insert and could not. Exceeded the maximum number of 1000 records. Then I tried with Bulk, but I do not know if I did right or not, the fact is that it gives error. My Bulk is like this:

BULK INSERT CIDADE 
FROM 'C:\Lixo\Cidade_Brasil.txt'

And my txt is in this format:

(1, 'Afonso Cláudio', 8),
(2, 'Água Doce do Norte', 8),
(3, 'Águia Branca', 8),
(4, 'Alegre', 8),
(5, 'Alfredo Chaves', 8),
(6, 'Alto Rio Novo', 8),
(7, 'Anchieta', 8),
(8, 'Apiacá', 8),
(9, 'Aracruz', 8),
(10, 'Atilio Vivacqua', 8),
(11, 'Baixo Guandu', 8),
(12, 'Barra de São Francisco', 8),
(13, 'Boa Esperança', 8),
......;

And that’s the error message:

Message 4832, Level 16, Status 1, Line 3 Bulk loading: end unexpected file in data file. Message 7399, Level 16, State 1, Line 3 The OLE DB provider "BULK" for the server linked "(null)" reported an error. The provider did not provide error information. Message 7330, Level 16, Status 2, Line 3 Unable to fetch a line from the OLE DB "BULK" provider to the linked server "(null)".

  • Names that have simple quotes, for example olho d'agua are escaped?

  • I didn’t even think about it. I will correct them all. But the syntax of Bulk is the same?

  • So back to your example, eye dagua está assim: `(161, 'Olho dWater of the Flowers', 2),`, without quotation marks and yes with "crase" and I realized it is so for all.

1 answer

2

I created the MUNICIPIOS table:

CREATE TABLE MUNICIPIOS (
   id int,
   dscidade varchar(35),
   estado varchar(2))

I prepared the import file:

  1,Abadia de Goiás,GO;
  2,Abadia dos Dourados,MG;
  3,Abadiânia,GO;
  4,Abaeté,MG;
  5,Abaetetuba,PA;
  6,Abaiara,CE;
  7,Abaíra,BA;
  8,Abaré,BA;
  9,Alvorada d'Oeste,RO;
 10,Abdon Batista,SC;
 11,Abelardo Luz,SC;
 12,Alta Floresta d'Oeste,RO;
 13,Abre-Campo,MG;
 14,Abreu e Lima,PE;   

Note that I have fields with 'but this will not cause problems.

My import script for this file will look like this:

BULK INSERT MUNICIPIOS
FROM 'C:\TEMP\MUNICIPIOS.TXT'
WITH
 ( ROWTERMINATOR = ';',  
   FIELDTERMINATOR = ',',
   LASTROW = 14 )

I specify which is the record separator, which is the column separator and how many lines the import file has.

  • Tomorrow when I get to the company, I’ll try that approach with those specs.

  • I was unable to make it work according to the example of Mr Reginaldorigo.

  • @pnet What error are you getting?

  • I think it has to do with names of cities that have an apostrophe in their composition. I tried otherwise, without Bulk and it didn’t work. I’ll do another post about this new approach.

  • See that in the example I left cities with apostrophes to test this. In the case of the example I would have problems with the comma or the point and comma because they are being used as markers and not with another character. I tested on Sqlserver 2012 and ran smoothly as this in the example.

  • So Reginaldo, I think the problem is there. I tried Bulk with three records only and it wasn’t. Well, as I needed to, I downloaded a BD(.dpk) from the net, restored it on my server, and imported the data from that table into my table. But I’ll still test with Bulk the question.

  • It’s weird because it works normal here, if I input the 14 example records or the 5570 of the full listing. Put there the mistake you’re getting.

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.