Welcome to Dream.In.Code
Become an Expert!

Join 149,713 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,244 people online right now. Registration is fast and FREE... Join Now!




Insert from text file

 
Reply to this topicStart new topic

Insert from text file

realNoName
9 Feb, 2007 - 12:29 PM
Post #1

D.I.C Regular
***

Joined: 4 Dec, 2006
Posts: 311



Thanked: 5 times
My Contributions
I am taking a DB management class but i would really like to play with it at home so am trying to copy the db's to my computer so i did a simple select * from collect and saved the results as a csv so i have all the records

at home i made the db
CODE
create table collection
(
    BOOK_ID CHAR(5) NOT NULL,
    SCAN_CODE CHAR(6) NOT NULL,
    LIBRARY CHAR(8) NOT NULL,
    BOOK_STATUS CHAR(1) NOT NULL,
    DATE_LAST_OUT DATETIME NOT NULL,
    TIMES_CHECKED_OUT NUMERIC(4) NOT NULL,
    CHECK_OUT_INTERVAL CHAR(1) NOT NULL,
    COST NUMERIC(7,2) NULL,
    YEAR_ACQUIRED CHAR(4) NULL,
    LAST_DATE_UPDATED DATETIME NOT NULL
)

then tried to insert the data but then i get errors and have no idea what i need to do
CODE

BULK INSERT collection FROM 'C:\DB\collection.csv' WITH (FIELDTERMINATOR = ',')

Errors
QUOTE
Msg 4863, Level 16, State 1, Line 1
Bulk load data conversion error (truncation) for row 1, column 1 (BOOK_ID).
Msg 4866, Level 16, State 8, Line 1
The bulk load failed. The column is too long in the data file for row 1, column 10. Verify that the field terminator and row terminator are specified correctly.
Msg 7399, Level 16, State 1, Line 1
The OLE DB provider "BULK" for linked server "(null)" reported an error. The provider did not give any information about the error.
Msg 7330, Level 16, State 2, Line 1
Cannot fetch a row from OLE DB provider "BULK" for linked server "(null)"


Sample of data
QUOTE
00220,A63982,JCLS,R,1999-07-20 00:00:00.000,5,C,12.59,1981,1990-09-04 00:00:00.000
00807,A64129,JCLS,I,1999-08-02 00:00:00.000,6,C,NULL,1973,1990-10-22 00:00:00.000
00206,A65257,JCLS,I,1999-07-12 00:00:00.000,1,C,NULL,1980,1991-01-30 00:00:00.000
00931,A65258,JCLS,I,1999-12-22 00:00:00.000,9,B,8.95,1975,1990-03-07 00:00:00.000
00669,A65382,JCLS,O,1999-12-19 00:00:00.000,3,C,7.95,1971,1990-09-01 00:00:00.000


Thanks

This post has been edited by realNoName: 9 Feb, 2007 - 12:30 PM
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Insert From Text File
10 Feb, 2007 - 10:50 AM
Post #2

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,350



Thanked: 51 times
Dream Kudos: 25
My Contributions
What database software are you using? As the file was exported into a CSV format, each line is likely being viewed as a single entry by the DB - far too long for the fields specified.

Does your DB software have a GUI?
User is online!Profile CardPM
+Quote Post

realNoName
RE: Insert From Text File
10 Feb, 2007 - 11:01 AM
Post #3

D.I.C Regular
***

Joined: 4 Dec, 2006
Posts: 311



Thanked: 5 times
My Contributions
Saved from msSQL 05 and trying to import into msSQL 05

This post has been edited by realNoName: 10 Feb, 2007 - 11:03 AM
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Insert From Text File
10 Feb, 2007 - 03:12 PM
Post #4

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 7,306



Thanked: 66 times
Dream Kudos: 500
Expert In: Everything

My Contributions
The table where the data came from what are its' column attributes?

The fields will have to match exactly. Especially using char() fields.

They may only have 5 characters stored in them but if the actual field length is 6 then you will get a mismatch error.
User is offlineProfile CardPM
+Quote Post

realNoName
RE: Insert From Text File
11 Feb, 2007 - 09:12 AM
Post #5

D.I.C Regular
***

Joined: 4 Dec, 2006
Posts: 311



Thanked: 5 times
My Contributions
I got it to work... i did not have to change anything i just added only around 100 records at a time (there was 1769 total) and for some reason that worked
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 04:37AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month