zoukankan      html  css  js  c++  java
  • BCP使用笔记整理

    640?wx_fmt=jpeg


    一、BCP 简介


    大容量复制程序实用工具 (bcp) 可以在 Microsoft SQL Server 实例和用户指定格式的数据文件间大容量复制数据。 使用 bcp 实用工具可以将大量新行导入 SQL Server 表,或将表数据导出到数据文件。 除非与 queryout 选项一起使用,否则使用该实用工具不需要了解 Transact-SQL知识。 

    若要将数据导入表中,必须使用为该表创建的格式文件,或者必须了解表的结构以及对于该表中的列有效的数据类型。



    1、用法

    用法: bcp {dbtable | query} {in | out | queryout | format} 数据文件

      [-m 最大错误数]             [-f 格式化文件]       [-e 错误文件]

      [-F 首行]                   [-L 末行]             [-b 批大小]

      [-n 本机类型]               [-c 字符类型]         [-w 宽字符类型]

      [-N 将非文本保持为本机类型] [-V 文件格式版本]     [-q 带引号的标识符]

      [-C 代码页说明符]           [-t 字段终止符]       [-r 行终止符]

      [-i 输入文件]               [-o 输出文件]         [-a 数据包大小]

      [-S 服务器名称]             [-U 用户名]           [-P 密码]

      [-T 可信连接]               [-v 版本]             [-R 允许使用区域设置]

      [-k 保留空值]               [-E 保留标识值]

      [-h"加载提示"]              [-x 生成xml 格式化文件]

    2、BCP导出语句 cmd命令直接执行


    -t 自定义分隔符  -d 数据库名称 -S 服务器地址  -U 用户名 -P 密码


    BCP "select * from T_user" queryout d:T_user.txt -c -d"DB" -S"127.0.0.1" -U"sa" -P"sa" -t "$$"


    3、BCP导入语句


    BCP T_user in d:T_user.txt -c -d"DB" -S"127.0.0.1" -U"sa" -P"sa" -t "$$"

    3、SQL Server中中执行


    默认SQL Server 阻止了对组件“xp_cmdshell”的 过程“sys.xp_cmdshell”的访问,因为此组件已作为此服务器安全配置的一部分而被关闭。系统管理员可以通过使用 sp_configure 启用“xp_cmdshell”。有关启用“xp_cmdshell”的详细信息,请搜索 SQL Server 联机丛书中的“xp_cmdshell”。

    a.启用xp_cmdshell:

    -- 允许配置高级选项  

    EXEC master.sys.sp_configure 'show advanced options', 1  

    -- 重新配置  

    RECONFIGURE  

    -- 启用xp_cmdshell  

    EXEC master.sys.sp_configure 'xp_cmdshell', 1  

    --重新配置  

    RECONFIGURE

    b. 关闭xp_cmdshell:

    -- 允许配置高级选项  

    EXEC master.sys.sp_configure 'show advanced options', 1  

    -- 重新配置  

    RECONFIGURE  

    -- 禁用xp_cmdshell  

    EXEC master.sys.sp_configure 'xp_cmdshell', 0

    --重新配置  

    RECONFIGURE

    c 执行sql语句

    EXEC master..xp_cmdshell 'BCP "select * from T_user" queryout d:T_user.txt -c -d"DB" -S"127.0.0.1" -U"sa" -P"sa" -t "$$" '

    EXEC master..xp_cmdshell 'BCP T_user in d:T_user.txt -c -d"DB" -S"127.0.0.1" -U"sa" -P"sa" -t "$$" '



  • 相关阅读:
    DPDK安装方法 17.12.13
    numa.h:No such file or directory 解决方法
    17秋 软件工程 第六次作业 Beta冲刺 Scrum3
    17秋 软件工程 第六次作业 Beta冲刺 总结博客
    17秋 软件工程 第六次作业 Beta冲刺 Scrum2
    Paper Reviews and Presentations
    17秋 软件工程 第六次作业 Beta冲刺 Scrum1
    17秋 软件工程 第六次作业 Beta冲刺
    error: could not create '/System/Library/Frameworks/Python.framework/Versions/2.7/share': Operation not permitted
    17秋 软件工程 个人作业 软件产品案例分析
  • 原文地址:https://www.cnblogs.com/hgmyz/p/12351673.html
Copyright © 2011-2022 走看看