The simplest option for importing text data into a database is that Excel uses Openset,csv and txt with BULK insert to implement
1. Use OPENROWSET to import Excel into the database
Refer to "OpenRowSet usage"
2, use BULK INSERT to import TXT data into the database, text data using tab to split column, use newline character to split row.
--Create staging TableCreate Tabledbo.txt_staging (col1nvarchar(255), col2nvarchar(255), Col3nvarchar(255))Go--Populate DataBulk Insertdbo.txt_staging fromN'D:\test.txt' with(FieldTerminator= '\ t', Rowterminator= '\ n')
3. Use BULK INSERT to import CSV data into the database
The CSV file uses "," as the column delimiter, using "\ n" as the row delimiter
--Populate DataBulk Insertdbo.txt_staging fromN'D:\abc.csv' with(FieldTerminator=N',', Rowterminator=N'\ n', CODEPAGE=N'Raw')
Appendix
The syntax of the BULK INSERT is simplified as follows
bulk insert schema_name. table_name from data_file with (FieldTerminator = '
FieldTerminator ='field_terminator'
Specifies the field terminator to is used for char and widechar data files. The default field terminator is \ t (tab character).
Rowterminator ='row_terminator'
Specifies the row terminator to is used for char and widechar data files. The default row terminator is \ r \ n (newline character).
Reference doc:
BULK INSERT (Transact-SQL)
Import CSV and TXT data into the database