1  /  1  页   1 跳转 查看:6429

[技术文档] 批量执行脚本文件

批量执行脚本文件

批量执行脚本文件

--王成辉原创,转贴请注明出自微软BI开拓者www.windbi.com

--SQL2000中的方法
create table #T(id int identity(1,1),col varchar(100))
insert into #t exec master..xp_cmdshell 'dir E:\*.sql'
delete from #t where col not like '%.sql' or col is null
update #T set col=right(col,len(col)-36)  --这里的36可能需要你做相应的修改
declare @sql varchar(500),@id int,@id1 int
select @id=min(id),@id1=max(id) from #t
while @id<
=@id1
begin
  select @sql='isql -Usa -Ppassword -Sserver_name -ddb_name -iE:\'+col from #t where
id=@id
  exec master..xp_cmdshell @sql, no_output
  set @id=@id+1
end
drop table #T

----------------------------------------------------------------------
注:该方法在2005中也可以用,或者将isql改为sqlcmd也可以。由于SQL2005中的的xp_cmdshell默认是关闭的,所以要先启动。如果已经启动就不用再启动了。启动用下面的语句:
EXEC sp_configure 'show advanced options', 1
GO
RECONFIGURE
GO
EXEC sp_configure 'xp_cmdshell', 1
GO
RECONFIGURE
GO
最后编辑拓狼 最后编辑于 2007-07-17 09:11:41
虽有智慧,不如乘势;虽有鎡基,不如待时。
君子学以聚之,问以辨之,宽以居之,仁以行之。
独学而无友,则孤陋而寡闻。
 

回复:批量执行脚本文件

isql执行出错时,怎么办?
 

回复:批量执行脚本文件

厉害,哪不是批量导入XLS也是可行的了!
中国数据库联盟 :http://cndba.5d6d.com
 
1  /  1  页   1 跳转

版权所有 微软BI开拓者 

Powered by Discuz!NT 2.1.202    Copyright © 2001-2012 Comsenz Inc.
Processed in 0.078128 second(s) , 0 query.
返顶部