[转]How to Import a Text File into SQL Server 2012
Importing a Text File into SQL Server 2012 using the OpenRowSet() Function The OPENROWSET bulk row set provider is accessed by calling the OPENROWSET function and specifying the BULK option. The OPENROWSET(BULK…) function allows you to access remote data by connecting to a remote data source, such as a data file, through an OLE DB provider. To bulk import data, call OPENROWSET(BULK…) from a SELECT…FROM clause within an INSERT statement. The basic syntax for bulk importing data is: INSERT … SELECT * FROM OPENROWSET(BULK…) When used in an INSERT statement, OPENROWSET(BULK…) supports table hints. In addition to the regular table hints, such as TABLOCK, the BULK clause can accept the following specialized table hints: IGNORE_CONSTRAINTS (ignores only the CHECK constraints), IGNORE_TRIGGERS, KEEPDEFAULTS, and KEEPIDENTITY. This example imports text file into SQL-Server 2012 using OpenRowSet command. Step 1) Create a Data Table (corresponding to columns in text file) CREATE TABLE [dbo].[players](
[RK] [varchar](50) NULL,
[PLAYER] [varchar](50) NULL,
[Salary (US$)] [varchar](50) NULL
) ON [PRIMARY] Step 2) Create a Format File Specific to Text File The file is using SQL Server edition 11.0 (i.e. SQL Server 2012)
Table has 3 columns.
Each column can accept 0 to 50 chars.
Each column is tab separated \t.
Each new row is separated by new line char \r\n. Players.fmt 11.0
3
1 SQLCHAR 0 50 “\t” 1 RK Latin1_General_CI_AI
2 SQLCHAR 0 50 “\t” 2 PLAYER Latin1_General_CI_AI
3 SQLCHAR 0 50 “\r\n” 3 Salary Latin1_General_CI_AI Step 3) Test OpenRowSet Command Select document.* from openrowset(BULK N’C:\players.txt’,formatfile=N’c:\player.fmt’ ,firstrow=2) as document. Step 4) Insert into Players Datatable Insert into [dbo].[players]
select document.* from openrowset(BULK N’C:\players.txt’,formatfile=N’c:\players.fmt’,firstrow=2) as document Players.txt RK PLAYER Salary
1 Alex Rodriguez 30,000,000
2 CC Sabathia 24,285,714
3 Mark Teixeira 23,125,000
4 Ichiro Suzuki 18,000,000
5 Derek Jeter 15,729,365
6 Mariano Rivera 14,940,025
7 Robinson Cano 14,000,000 Step 5) Verify Data in Players Select * from dbo.players For more Microsoft Technical Training information visit www.directionstraining.com or call 1-855-575-8900.
[转]How to Import a Text File into SQL Server 2012的更多相关文章
- SQL Server 2012附加数据库时,错误提示如下:尝试打开或创建物理时,CREATE FILE 遇到操作系统错误 5(拒绝访问。)
错误提示:Create File遇到操作系统错误5(拒绝访问) 解决方案: 在所有程序-SQL Server 2012-"SQL Server 配置管理器",点击"SQL ...
- SQL SERVER – Import CSV File Into SQL Server Using Bulk Insert – Load Comma Delimited File Into SQL Server
CSV stands for Comma Separated Values, sometimes also called Comma Delimited Values. Create TestTabl ...
- import data from excel to sql server
https://www.c-sharpcorner.com/article/how-to-import-excel-data-in-sql-server-2014/ 需要注意的是,第一次是选择sour ...
- 6 ways to import data into SQL Server
I’m going to go over some methods to import data from text files into SQL Server today. The particul ...
- 安装“Microsoft SQL Server 2014 Management Objects”时报错"Error Writing to file: Microsoft.SqlServer.XEvent.Linq.dll."
问题: 当安装的软件依赖Microsoft SQL Server 2014 Management Objects时,会把这个组件打进安装包里,但是在服务器上安装时却报如下错误: “Error Writ ...
- create feature from text file
'''---------------------------------------------------------------------------------- Tool Name: Cre ...
- shell脚本执行时报"bad interpreter: Text file busy"的解决方法
在执行一个shell脚本时,遇到了“-bash: ./killSession.sh: /bin/bash: bad interpreter: Text file busy”错误提示,如下所示: [or ...
- eclipse的使用-------Text File Encoding没有GBK选项的设置
eclipse的使用-------Text File Encoding没有GBK选项的设置 2013-12-25 09:48:06 标签:java myeclipse使用 有一个项目是使用GBK编码的 ...
- Writing Text File From A Tabular Block In Oracle Forms
The example given below for writing text file or CSV using Text_IO package from a tabular block in O ...
随机推荐
- java 执行sql文件
# 背景 用例执行完毕,期望回滚数据,因此希望执行sql来回滚数据 # 步骤 直接show代码,借助的是mybatis的ScriptRunner /** * 执行xx库下的表备份脚本 * * @par ...
- 安装CentOS桌面环境
CentOS 作为服务器的操作系统是很常见的,但是因为需要稳定而没有很时髦的更新,所以很少做为桌面环境.在服务器上通常不需要安装桌面环境,最小化地安装 CentOS(也就是 minimal CentO ...
- Windows下常用的100个CMD指令以及常见的操作
gpedit.msc—–组策略 2. sndrec32——-录音机 3. Nslookup——-IP地址侦测器 ,是一个 监测网络中 DNS 服务器是否能正确实现域名解析的命令行工具. 它在 Wind ...
- 《Python黑帽子:黑客与渗透测试编程之道》 Windows下木马的常用功能
有趣的键盘记录: 安装pyHook: http://nchc.dl.sourceforge.net/project/pyhook/pyhook/1.5.1/pyHook-1.5.1.win32-py2 ...
- LCS2 - Longest Common Substring II(spoj1812)(sam(后缀自动机)+多串LCS)
A string is finite sequence of characters over a non-empty finite set \(\sum\). In this problem, \(\ ...
- HDU 1024 最大M字段和
一道关于求最大M字段和的问题,翻译完题之后感觉很简单但就是写不来,后来仿佛推到一个dp式子了,对,仿佛...然后抄袭了个式子,嘿,和我的式子大体相似,然后就是很玄学的优化了...不多瞎bb了 1.首先 ...
- mariadb审计日志通过 logstash导入 hive
我们使用的 mariadb, 用的这个审计工具 https://mariadb.com/kb/en/library/mariadb-audit-plugin/ 这个工具一点都不考虑后期对数据的处理, ...
- Xshell连接不上虚拟机Linux系统
以下是我在尝试网上各种办法之后总结的最优解决办法: 1.先在主机上检查虚拟机相关的必要的服务是否都已经启动 2.检查虚拟机系统防火墙是否处于关闭状态 3.检查虚拟机系统的ssh服务是否已经启动 4.检 ...
- POJ 1087
#include<iostream> #include<stdio.h> #include<string> #define MAXN 105 using names ...
- A Node Influence Based Label Propagation Algorithm for Community detection in networks 文章算法实现的疑问
这是我最近看到的一篇论文,思路还是很清晰的,就是改进的LPA算法.改进的地方在两个方面: (1)结合K-shell算法计算量了节点重重要度NI(node importance),标签更新顺序则按照NI ...