sql server 内置ETL工具学习

常用的导入方式:bcp, BULK INSERT,OPENROWSET和 SSIS。

BCP

BCP全称BULK COPY PROGRAM

有以下特点:

  • 命令行工具
  • 导出为文本文件

在异构数据库之间迁移 数据时,这个一个比较通用的方法,因为基本上所有的数据库都支持文本文件。

命令参考文档@MSDN

导出一张表

导出数据文件

bcp AdventureWorks2012.HumanResources.Employee OUT d:\dump\Employee.txt -c"char" -t"|" -r\n -T

其中 -c表示导出用的字符类型,默认为char

-t表示字段分隔符

-r表示换行符

-T表示使用本地操作系统认证

bcp AdventureWorks2012.HumanResources.Employee OUT d:\dump\Employee.txt -c"char" -t"|" -r"\n" -U"sa" -P"sql2015" -S"RJD08"

其中-U表示用户名

-P表示密码

-S表示服务器名

导出数据格式

bcp AdventureWorks2012.HumanResources.Employee format nul -f d:\dump\Employee_format.fmt -t"|" -c -r"\n" -T

其中-f 表示导出的是format文件

数据导入

新建表结构

导入时需要新建目标表结构,使用select * into创建方式。

use AdventureWorks2012
go select * into HumanResources.Employee_temp
from HumanResources.Employee where 1=2; select * from HumanResources.Employee_temp;

执行导入

使用bcp

命令: bcp …in 格式: -f format_file

BCP AdventureWorks2012.HumanResources.Employee_temp in d:\dump\Employee.txt -c -f d:\dump\Employee_format.fmt -T

BULK insert

可以在ssms中执行

DELETE HumanResources.Employee_temp
GO
SELECT COUNT(*) FROM HumanResources.Employee_temp
GO
BULK INSERT HumanResources.Employee_temp
FROM 'd:\dump\Employee.txt'
WITH (FORMATFILE = 'd:\dump\Employee_format.fmt');
GO
SELECT COUNT(*) FROM HumanResources.Employee_temp
GO

OPENROWSET 大容量行集提供程序

同样是在ssms中执行

DELETE HumanResources.Employee_temp
GO
SELECT COUNT(*) FROM HumanResources.Employee_temp
GO
INSERT INTO HumanResources.Employee_temp
SELECT *
FROM OPENROWSET(BULK 'd:\dump\Employee.txt',
FORMATFILE='d:\dump\Employee_format.fmt'
) as t1;
GO
SELECT COUNT(*) FROM HumanResources.Employee_temp
GO

其它

bcp也可以在ssms中执行,可以用以下命令实现。

-- To allow advanced options to be changed.
EXEC sp_configure 'show advanced options', 1
GO
-- To update the currently configured value for advanced options.
RECONFIGURE
GO
-- To enable the feature.
EXEC sp_configure 'xp_cmdshell', 1
GO
-- To update the currently configured value for this feature.
RECONFIGURE
GO

sql server 内置ETL工具学习(一) BCP篇的更多相关文章

  1. SQL Server内置的HTAP技术

    SQL Server内置的HTAP技术 目录 背景 SQL Server在OLAP上的发展 SQL Server的初代HTAP SQL Server逐渐增强的HTAP SQL Server列存总结 H ...

  2. SQL Server 内置函数、临时对象、流程控制

    SQL Server 内置函数 日期时间函数 --返回当前系统日期时间 select getdate() as [datetime],sysdatetime() as [datetime2] getd ...

  3. 10、SQL Server 内置函数、临时对象、流程控制

    SQL Server 内置函数 日期时间函数 --返回当前系统日期时间 select getdate() as [datetime],sysdatetime() as [datetime2] getd ...

  4. sql server内置存储过程、查看系统信息

    1.检索关键字:sql server内置存储过程,sql server查看系统信息 2.查看磁盘空间:EXEC master.dbo.xp_fixeddrives , --查看各个数据库所在磁盘情况S ...

  5. 总结Sql Server内置函数实现MD5加密

    --MD5加密 --HashBytes ('加密方式', '待加密的值') --加密方式= MD2 | MD4 | MD5 | SHA | SHA1 --返回值类型:varbinary(maximum ...

  6. sql server内置函数

    MSDN标准文档:https://msdn.microsoft.com/zh-cn/library/ff848784(v=sql.120).aspx 配置函数 select @@servername ...

  7. mysql 内置函数和sql server 内置函数的区别

    以下函数均没有对参数做说明,使用的使用需要了解其参数内容 数据库 sql server mysql oracle 举例 获得当前系统时间 getdate() now() sysdate  注意不是函数 ...

  8. SQL Server ->> 内置标量函数TRY_PARSE、TRY_CAST和TRY_CONVERT的各自特点和区别

    SQL Server到了目前的2014版本有三个函数是用来转换数据格式的.虽说之前版本中已经有CAST和CONVERT这两个函数来干这个事情.问题是,一旦往目标数据类型转换失败就会造成报错. TRY_ ...

  9. SQL Server 内置函数实现MD5加密

    一.MD5加密 HASHBYTES ('加密方式', '待加密的值')     加密方式= MD2 | MD4 | MD5 | SHA | SHA1     返回值类型:varbinary(maxim ...

随机推荐

  1. VBA读取固定文件夹中txt内容

    Sub OneTxt() '打开一个txt文件 Dim Filename As Variant, extLine&, mArr() As String Dim i%, j%, txtpath ...

  2. 小记:获取post和get请求。

    package com.lixu.httpget_post; import java.io.ByteArrayOutputStream; import java.io.IOException; imp ...

  3. P264练习题1.2题

    package 集合; import java.util.*; public class fourteen { public static void main(String[] args) { //1 ...

  4. numpy 总结

    1.array.sum() from numpy import * import operator group = array([[1.0,1.1],[1.0,1.0],[0,0],[0,0.1]]) ...

  5. Sublime Text 3 插件安装

    1.安装 Package Control 组件 sublime菜单栏->view->show console: 输入以下命令回车: import urllib.request,os; pf ...

  6. 兼容 IE,firfox 的时间日期出现 NaN

      //当前日期加上天数后的新日期.function AddDays(days) { var d = new Date(); var year = d.getFullYear(); var day = ...

  7. iOS如何生成.a文件

    首先来谈谈为何要使用.a文件 Objective-c语言有.h .m 文件组成.静态库可以将 .m文件封装成一个.a文件,第三方应用程序只需要拿到这个.a文件和代码对应的.h文件即可使用静态库中封装的 ...

  8. Matlab:max函数

    Matlab中max函数在矩阵中求函数大小的实例如下: C = max(A)返回一个数组各不同维中的最大元素.如果A是一个向量,max(A)返回A中的最大元素.如果A是一个矩阵,max(A)将A的每一 ...

  9. matlab调用opencv函数的配置

    环境: VS2010 活动解决方案平台x64 WIN 8.1 Opencv 2.4.3 Matlab 2012a 1.  首先保证vs2010能正确调用opencv函数, 2.  Matlab中选择编 ...

  10. Matlab与C/C++联合编程之Matlab以MEX方式调用C/C++代码(一)

    MEX文件是一种可在matlab环境中调用的C语言(或fortran)衍生程序,mex的编译结果实际上就是一个带输出函数mexFunction 的dll文件. 中文名 mex文件 外文名 MATLAB ...