How to import text, Excel, and access data to SQL Server

Source: Internet
Author: User

As follows: CopyCode The Code is as follows: "awu", "102300", "ZX240-3", "2609997000", "2609997000", "3016924000", "3091775000 ","","", "qcr0000285 ",""
"Aye", "001800", "zx60", "2609997000", "2609997000", "3016924000 ","","","","","", ""

Although the project has developed applicationsProgram, Parses similar text files and stores records in the database, but the efficiency is obviously less than that of batch import. To save time, starting from pm, I decided to import the text file to excel first, and then import the Excel file to SQL Server. (Because some of the previous backup work is the inverse method of this operation ).

Open excel2007, and then select to open the text file of the data source. The system automatically enters the "text import wizard ".
Step 1, select the field segmentation method, this example uses the "segmentation symbol", adjust the text file encoding mode (UTF-8, ANSI, etc.), it is guaranteed that the imported data is not garbled.
Step 2: select the separator and text recognition symbol (Great! How to remove double quotation marks ).
Step 3: Set the data type (General, text, and date) for each column ). Click Finish!
Two details are prompted:
1. for example, if the second field of the second row of the sample data is "001800", if you follow the "regular" type in the third step of the import, the front-end "00" will be removed, similar to the number processing method, if you want to retain it, select the "text" type.
2. Sometimes there are inevitable format problems in the source data, especially when importing database forms with strong constraints, an error is reported. In this case, you have to check the Excel data based on the error message. During the test, the comma appears inside the "," Double quotation mark, causing data to be unable to be imported. Multiple double quotes: "" and so on.
3. After data is imported into excel, it is best to insert a row before the first row and enter the field name of the corresponding form of the database. We do not know whether this trip can be implemented. Please prove it in practice :)

Therefore, we recommend that you first import text files to access and import them to SQL Server through access. The advantage is that the data type of access is more similar to that of SQL Server. In this way, when a text file is imported into access, the validity of the data is strictly verified to avoid a lot of trouble in the future.

the import method is similar. For a brief introduction, open access2007 and select "external data"-"Text File". After selecting a text file, the "Import text wizard" appears ".
Step 1: select a fixed width or separator.
Step 2: select the delimiter type and text identifier, and select "the first line contains the field name ".
Step 3: Set the field name and field type (the most valuable one ).
Step 4: whether to create a primary key.
Step 5: complete!
a slight error is prompted:
some text files may contain garbled characters at the front end of the first line during access import and preview. It doesn't matter. Open source text files, press enter at the beginning of the line, and create an empty line. After the data is imported, the first row of records is deleted again in the access table.
at last, use the SQL Server Enterprise Manager to select the form to be re-imported, right-click the form and choose import data. Continue to the next step: SQL server will strictly match the data type of the record when importing data. If the data type does not match, the data import of this batch will fail.
OK. share these items first. For more tips, please join us. The active use of the office series and the clever use of the MS software are really powerful, and you need to mine them slowly :) more SQL server data import skills, I also need to learn more!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.