SQL SERVER uses BULK INSERT to BULK INSERT data from a TXT file into a table (1)

Source: Internet
Author: User
Tags bulk insert

1/Set up data tables first

CREATE TABLE basicmsg
(
Recvtime FLOAT not NULL,--Receive time, no data with the same time
AA INT not NULL,--24-bit address code.
Flightid Varchar () NULL,-flight number
)

2/Set up stored procedures

Use Df17datapro
IF EXISTS (SELECT * from SYS.) Procedures WHERE object_id = object_id (N ' [dbo].[ Bulkdataproc]))
DROP PROC [DBO]. [Bulkdataproc]
GO
--Output NIC values in each range
CREATE PROCEDURE Bulkdataproc
As
SET NOCOUNT on
BULK INSERT basicmsg from ' d:\\writedatafile.txt '--location with filename//BasicMsg11
With
(
--KeepIdentity,
FieldTerminator = ', ',
Rowterminator = ' \ n '
)
GO
EXECute Bulkdataproc--1

3/writedatafile.txt File Content Format

43255,7867628,cca1519

4/Precautions

--Perform the above steps in order to insert the contents of the file into the database;

--Use the above method to make an error when there are self-increment columns in the data table; see the second article, "SQL SERVER uses BULK INSERT to BULK INSERT data from a TXT file into a table (2)"
 

SQL SERVER uses BULK INSERT to BULK INSERT data from a TXT file into a table (1)

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.