Now: Tutorial for Web and Software Design > Database > MS SQL > Database Content
> Load TXT File using OPENROWSET function [Bookmark it]
Load TXT File using OPENROWSET function
SQL Scripts
February 23, 2006
Load TXT File using OPENROWSET function


>>Script Language and Platform: T-SQL/ SQL SERVER
Let's say we have txt file dts_2_11012005.txt. The file is located in subdirectory C:STUDIESsql_serveropenrowset_txt_to_sql.

dts_2_11012005.txt is a Tab Delimited file, which contains following columns :


emp_id       Width 9

fname        Width 8

minit        Width 1

lname        Width 9

job_id       Width 2

job_lvl      Width 3

pub_id       Width 4

hire_date    Width 10

To load this file in SQL Database we need to create Schema.ini file in The same subdirectory : C:STUDIESsql_serveropenrowset_txt_to_sql. Detailed description of Schema.ini file you can find in SQL SERVER book online.

Schema.ini file for dts_2_11012005.txt should look like :

[dts_2_11012005.txt]

ColNameHeader=True

Format=TabDelimited

MaxScanRows=0

CharacterSet=ANSI

Col1=emp_id Text Width 9

Col2=fname Text Width 8

Col3=minit Text Width 1

Col4=lname Text Width 9

Col5=job_id Text Width 2

Col6=job_lvl Text Width 3

Col7=pub_id Text Width 4

Col8=hire_date date Width 10

Now we can run from Query Analyzer the code below:

Author: Boris Bondar



 Use pubs

SELECT * INTO txtmport FROM 

OPENROWSET(''Microsoft.Jet.OLEDB.4.0'',

''Text;Database=C:STUDIESsql_serveropenrowset_txt_to_sql'',

''SELECT * FROM dts_2_11012005.txt'') 

Download Script:


Disclaimer: We hope that the information on these script pages is valuable to you. Your use of the information contained in these pages, however, is at your sole risk. All information on these pages is provided "as -is", without any warranty, whether express or implied, of its accuracy, completeness, or fitness for a particular purpose... Disclaimer Continued


Back to Database Journal Home

[Bookmark][Print] [Close][To Top]
  • Prev Article-Database:

  • Next Article-Database:
  • Related Materias
    No Related FoundDatabase
    Topics
    Photoshop Tutorial
     

    Special Effect

      3D Effect
      Photoshop Articles
    Programming Tutorial
     

    C/C++ Tutorial

      Visual Basic
      C# Tutorial
    Database Tutorial
     

    MySQL Tutorial

      MS SQL Tutorial
      Oracle Tutorial
    Graphic Design Tutorial
     

    Coreldraw Tutorial

      Illustrator Tutorial
      3D Graphics Articles
    Webmaster Articles
     

    Domain Service

      Web Hosting
      Site Promotion
    Java Tutorial&Articles
     

    Java Servlets

      JavaEE Tutorial
     

    JavaBeans Tutorial

    XML Tutorial&Articles
     

    XML Style Tutorial

      AJAX Tutorial
      XML Mobile
    Flash Tutorial&Articles
     

    Flash Video

      Action Script
      Flash Articles
    OS Tutorial&Articles
     

    Linux Tutorial

      Symbian Tutorial
      MacOS Tutorial