Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
JaseDytec
Starting Member
14 Posts |
Posted - 2008-08-04 : 06:32:12
|
| Hi ppl.I'm new to programming, sql server and having a few problems with creating a query to bulk import data from a csv file to sql database. How would i modify the following query so that SQL Express can automatically insert an ID to the data. There are topics on this on the msdn but they are to hard for a novice to follow.USE [HumsDataCentre]GO--Add dataBULK INSERT ETI FROM '(file path)' WITH ( FIRSTROW = 2, FIELDTERMINATOR = ',', ROWTERMINATOR = '\n' ) GOSELECT * FROM ETIGOThe CSV file looks like thisDevice,Duration,UnitsA, 5, hoursMy sql table has the following fieldsDevice ID, Device, Duration, UnitsPlease help, thanks Jason. |
|
|
matty
Posting Yak Master
161 Posts |
Posted - 2008-08-04 : 06:41:05
|
| Set Device ID as an identity column |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-08-04 : 13:19:17
|
| Use[Device ID] int IDENTITY(1,1)in table definition |
 |
|
|
JaseDytec
Starting Member
14 Posts |
Posted - 2008-08-11 : 08:37:10
|
| Sorry i wasn't too clear, i need to tell the bulk insert to copy the data into the last three columns, Device, Duration, Units so that SQL can auto insert an ID. |
 |
|
|
JaseDytec
Starting Member
14 Posts |
Posted - 2008-08-11 : 08:39:31
|
| I think i need to use a format file, but i dont know how to? |
 |
|
|
|
|
|
|
|