recent

Titulo

Bulk Insert

Bulk Insert: MS Sql Server

BULK INSERT imports a data file into a database table or view in a user-specified format in SQL Server
BULK INSERT databasename.dbo.tablename
  FROM 'C:\demo\products.txt'
  WITH
    (
      fieldterminator='|',  -- Field terminator
      rowterminator='\n', --New line charter
      firstrow=2  --start with second row
    )
The above Bulk Insert statement loads txt file data into a Sql database. You don't always get data in a txt file, excel sheet is another frequently used in storing data. Lets write a bulk statement to insert data from a for Excel Document.
  1.  Open Excel Document. If any column contain comma, highlight the column data and convert them to text. If you don't convert it, you will have problem loading it into a table.
  2.  Save the excel doc as CSV file.
Now,
BULK INSERT databasename.dbo.tablename
  FROM 'C:\demo\products.csv'
  WITH
    (
      fieldterminator=',',  -- Field terminator
      rowterminator'\n', --New line charter
      firstrow=2  --start with second row
    )
You can now load data from a file to a database using Bulk Insert.
Quiz: How do you move data from one table to another in a different database?

Interested in working with me? I can be reached at pbaniya04[at]gmail.com for any questions, consulting opportunities or you may drop a line to say HELLO. Thank your again for visiting my blog and looking forward to serving you more.

Have a Database-ious Day!

No comments

Powered by Blogger.