背景:sql server数据库里的表结构 有个时间字段,格式为 2012/12/1 15:40:03
1.使用BCP从SQL Server 2012将表导出为xls.
--简单导出表
exec master..xp_cmdshell 'bcp db_oa.dbo.T_User_list out c:\a.xls -c -T' --"-T"信任连接
exec master..xp_cmdshell 'bcp db_oa.dbo.T_User_list out c:\a.txt -c -Usa -Pxxxxx'
--过滤导出表
exec master..xp_cmdshell 'bcp "select top 3 * from db_oa.dbo.t_user_list" queryout c:\a.txt -c -T'
--简单导入表
exec master..xp_cmdshell 'bcp db_oa.dbo.T_User_list_2 in c:\a.txt -c -T'
exec master..xp_cmdshell 'bcp db_oa.dbo.T_User_list_2 in c:\a.txt -c -T -E' --加上"-E"启用identity_insert on
http://www.cnblogs.com/qanholas/archive/2011/07/05/2098616.html
2.时间字段的处理
在Excel里处理时间字段的显示
选中整列---右键---设置单元格格式---自定义---类型中写入 e/m/d h:mm:ss 或 YYYY/M/D H:MM:SS 确定
处理完成导出为csv文件
3.使用SQL Developer导入CSV
在设置格式地方 日期的格式须设置为 YYYY/MM/DD HH24:MI:SS
2017年1月13更新
SQL Server如何启用xp_cmdshell组件
http://www.cnblogs.com/atree/p/SQL_SERVER_xp_cmdshell.html
通过查询分析器,选择Master数据库,然后执行以下SQL内容:
sp_configure 'show advanced options',1 reconfigure go sp_configure 'xp_cmdshell',1 reconfigure go
执行结果:
配置选项 'show advanced options' 已从 0 更改为 1。请运行 RECONFIGURE 语句进行安装。
配置选项 'xp_cmdshell' 已从 0 更改为 1。请运行 RECONFIGURE 语句进行安装。
如需关闭只需将“sp_configure 'xp_cmdshell',1”改为“sp_configure 'xp_cmdshell',0”即可。
http://blog.sina.com.cn/s/blog_6d357c8a0101imoi.html
sql 2008 r2 输出sql脚本文件 报错。bcp 不是内部或外部命令,也不是可运行的程序,只要把C:\Program