码迷,mamicode.com
首页 > 其他好文 > 详细

bcp篇

时间:2016-06-30 14:06:59      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:

使用一个死循环insert into测试数据库最大写入速度:

use [iTest];

declare @index int;
set @index=0;

while @index>=0
begin
    set @index=@index+1;
    INSERT into [g].[MR]
               ([TimeStamp],[RTime],[STime],[ETime],[Period],[ObjID],[SID],[CID]
               ,[Ueid],[GId],[Code],[ScEarfcn],[ScPCI],[ScRSRP],[ScRSRQ]
               ,[ScRTTD],[ScPHR],[ScAOA],[ScSinrUL],[ScRIP])
         VALUES
               (GETDATE(),GETDATE(),GETDATE(),GETDATE()
               ,1,11,22,33,44,44,1222,22,33
               ,44,55,66,77,88,99,00,111,null);
end
GO

结果发现一个问题,写入数据库iTest.mdf的速度只有几百千字节每秒,而写入iTest_log.ldf的速度也是几百字千节每秒,但是写入日志的速度要要多于数据库文件的速度,约在4倍的速度。他们两个之和才有将近1M字节每秒。

显然是写入有问题的。

xp_cmdshell 怎么开启

http://www.cnblogs.com/atree/p/SQL_SERVER_xp_cmdshell.html

sp_configure show_advanced options,1;
reconfigure
go 
sp_configure xp_cmdshell,1;
reconfigure
go

bcp 总结:http://rsljdkt.iteye.com/blog/1147707

bcp需要登录账户,数据库服务器\数据库实例信息: http://blog.sina.com.cn/s/blog_7ed5a808010140sl.html

创建格式化文件 (SQL Server):https://msdn.microsoft.com/zh-cn/library/ms191516.aspx

bcp工具使用MSDN文档:https://msdn.microsoft.com/zh-cn/library/ms162802.aspx

使用 BULK INSERT 或 OPENROWSET(BULK...) 导入大容量数据(SQL Server)MSDN文档:https://msdn.microsoft.com/zh-cn/library/ms175915.aspx

use iTest;
exec master..xp_cmdshell BCP itest.g.mr out c:/mr.txt -c -S.\work -UN_p_r -PN2

--begin transaction x1
truncate table itest.g.mr;
select top 1 * from itest.g.mr;
exec master..xp_cmdshell bcp itest.g.mr in c:/mr.txt -c -S.\work -UN_p_r -PN2
select top 1 * from itest.g.mr;
--rollback transaction x1;

 

bcp篇

标签:

原文地址:http://www.cnblogs.com/yy3b2007com/p/5629569.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!