Monday, May 18, 2015

BULK INSERT in T-SQL

BULK INSERT dbo.MyTable
FROM 'C:\Whatever\stuff.txt'
WITH (ROWTERMINATOR='0x0a');

 
 

This assumes that MyTable has one column that is a varchar or nvarchar type and that stuff.txt is a WordPad file full of little blobs of copy separated by line breaks. Each line will end up as row value for the one column in MyTable which may then be queried anew to have its goodies (now in a database table and not a flat file) made sense of in other ways. MyTable will probably then just be dropped like so:

DROP TABLE dbo.MyTable

 
 

0x0a signifies the line breaks. This factoid makes this blog posting a little more informative than this one.

No comments:

Post a Comment