日期:2014-05-18  浏览次数:20719 次

疯了,求sqlcmd的详细执行方式
sqlcmd代码(D:\test.sql),用于远程导入数据,导入前要删除之前的表:

if exists(select 1 from sysobjects where id=object_id('test'))
begin
  truncate table test;
  drop table test;
end

create table test(
id int;
)

!!bcp mytest.dbo.test in D:\test.txt -S 192.168.1.123 -U sa -P 123 -c -t "|""" -b 20000

在cmd中执行 sqlcmd -S 192.168.1.123 -U sa -P 123 -d mytest -V 1 -b -i "D:\test.sql"
结果显示有导入数据,可去数据库查询一条记录都没有,这是怎么回事啊?难道执行顺序不是一行一行来?而是先导入,然后把表删了?不可能啊,我郁闷死了

------解决方案--------------------
兄台每次问的问题都比较有难度啊,上次的也没说我回答的对不对


if exists(select 1 from sysobjects where id=object_id('test'))
begin
truncate table test;
drop table test;
end
go
create table test(
id int
)
go
!!bcp mytest.dbo.test in D:\test.txt -S 192.168.1.123 -U sa -P 123 -c -t "|""" -b 20000

语句之间加go 即可解决

------解决方案--------------------
加go试试