Solved

insert multiple rows into MSSQL from csv file

Posted on 2010-11-10
6
599 Views
Last Modified: 2012-05-10
Hi, I'm using MS SQL server management studio express. I have a table that looks like this:

ID, cust_name, cust_email, cust, cust_bday, cust_aniversary

I also have a csv file which only contains a list of email addresses, it looks like this:

a455@hughes.net 
aabeson@yahoo.com 
abean1313@aol.com 
abischoff@columbus.rr.com 
abradbee@kent.edu 
acyoung@ymail.com 

I would like to get these into the database and only need them to go into the cust_email column, the other columns can be blank (of course id will auto populate).

What is the best way to do this? Thanks.
0
Comment
Question by:elliottbenzle
6 Comments
 
LVL 7

Accepted Solution

by:
mkobrin earned 250 total points
ID: 34109087
SQL Server has a data Import wizard that will help you do this.

Right click on your data base, then select all tasks, then select import data, and follow the wizard. There will be options for you to match fields, ignore fields etc. Pretty easy to use.

Regards,

Mike
0
 
LVL 76

Expert Comment

by:arnold
ID: 34109152
http://dev.mysql.com/doc/refman/5.1/en/load-data.html

load data infile [filename] into table [tablename] (cust_email)

The items in [] mean that they need to be replaced with the correct information.
note that if you have any column that is defined as not null and does not have a default defined, the attempt will fail.

A similar option available in MS SQL:
http://msdn.microsoft.com/en-us/library/ms188365.aspx

bulk insert requires that all columns be present in the CSV since there is no way to designate the column to which the data belongs without using a format file.
http://msdn.microsoft.com/en-us/library/ms178129.aspx or using an alternative mechanism of using insert in conjunction with bulk or other tools that would convert the CSV file for use with the insert.
0
 
LVL 7

Expert Comment

by:rashmi_vaghela
ID: 34109221
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 15

Assisted Solution

by:AmmarR
AmmarR earned 250 total points
ID: 34109348
Just as mkobrin: mentioned

use the SQL import wizard, chose your csv file as datasource and your sql table as destination
and click on Edit mapping button, you will get the Columns mapping window, select only the cust_email column
and continue your wizard

check screen shots
Map.png
Output.png
0
 
LVL 6

Expert Comment

by:subhashpunia
ID: 34109561
0
 
LVL 21

Expert Comment

by:Alpesh Patel
ID: 34110043
Yes, to do that, In import export wizard have to set mapping and set customerID as identity.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now