首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

疯了,求sqlcmd的详细实施方式

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

疯了,求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试试

热点排行