再来一贴,如何提高插入性能

zjh222 2009-09-22 11:47:23

create table TT(ID numeric(10),name char(20),Englist numeric(5,2),physics numeric(5,2));
go
alter proc tpro
as
begin tran
insert into TT(ID,name,Englist,physics) values(3,'张三',89,98);
commit tran


go

go
begin tran
declare @II int;
set @II=1;
while @II<10000
begin
exec tpro;
end;
commit tran
go

select COUNT(*) from TT;

--我的天啦,8分钟还没有完,我只有中止执了....也不知要多久..
--大家有没有更快的办法


...全文
194 15 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
lg314 2009-09-22
  • 打赏
  • 举报
回复
set nocount on
begin tran
declare @II int;
set @II=1;
while @II<10000
begin
exec tpro;
set @II=@II+1
end;
commit tran
set nocount off
lg314 2009-09-22
  • 打赏
  • 举报
回复
begin tran 
insert into TT(ID,name,Englist,physics) values(3,'张三',89,98);
commit tran

这里是begin tran和commit tran是多余的

IF @@TRANCOUNT > 0 COMMIT TRAN
执行几次把没有提交的事务提交上去

set nocount on
begin tran
declare @II int;
set @II=1;
while @II<10000
begin
exec tpro;
end;
commit tran
set nocount off


这样也会快一倍多

zjh222 2009-09-22
  • 打赏
  • 举报
回复
这个可用于并发测试吗??呵呵..
zjh222 2009-09-22
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 fredrickhu 的回复:]
引用 1 楼 billpu 的回复:
删除索引

...
[/Quote]


go
begin tran --如何事务,不用事务会很慢
declare @II int;
set @II=1;
while @II<10000
begin
exec tpro;
set @II=@II+1;--弄丢了,执行是有的
end;
commit tran
go
lg314 2009-09-22
  • 打赏
  • 举报
回复
...
你看看@II有没有自增
sdhdy 2009-09-22
  • 打赏
  • 举报
回复
begin tran 
declare @II int;
set @II=1;
while @II<10000
begin
exec tpro;
--add
set @II=@II+1;
end;
commit tran
viva369 2009-09-22
  • 打赏
  • 举报
回复

while @II<10000
begin
exec tpro;
set @II = @II + 1
end;

sdhdy 2009-09-22
  • 打赏
  • 举报
回复
应该用不了多少时间,你的配置太低了吧?
billpu 2009-09-22
  • 打赏
  • 举报
回复
刚刚看了下...你是死循环...计数器永远小于1...
--小F-- 2009-09-22
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 billpu 的回复:]
删除索引
[/Quote]
...
zjh222 2009-09-22
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 billpu 的回复:]
删除索引
[/Quote]

我没有建索引,只建了个存储过程
soft_wsx 2009-09-22
  • 打赏
  • 举报
回复
你电脑有问题吧!我的用了38秒!
SQL77 2009-09-22
  • 打赏
  • 举报
回复
晕了,还来,乌龟大侠不是弄了吗
billpu 2009-09-22
  • 打赏
  • 举报
回复
删除索引

22,300

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧