mrfangzheng

Hope and fear are useless. Be confident, and always be prepared for the worst.
  首页  :: 新随笔  :: 联系 :: 管理

重建数据库脚本: OSql.exe不认UTF8, CMD.exe不认Unicode

Posted on 2008-11-14 11:29  mrfangzheng  阅读(558)  评论(0编辑  收藏  举报

由于SQL Server的OSql工具只认ANSI和Unicode, 不认UTF8, 所以尽量把Visual Studio的.sql文件用Unicode保存.

方法是修改SQL模版的encoding, 另存为Unicode格式, 文件模版的位置: \Microsoft Visual Studio 9.0\Common7\Tools\Templates\Database Project Items

 

CMD.exe不认Unicode? 我的机器上是这样的:(, 只好把所有的.bat改成ANSI

 

------------------------------------------用脚本重建数据库 RebuildDatabase.bat ------------------------------------------

REM @echo off
SET uid=sa
SET pwd=sa
SET db=YOUR_DATABASE_NAME
SET server=.
SET workingDrive=E:
SET workingPath=YOUR DIR

%workingDrive%
cd %workingPath%

dir *.sql /B sortorder N /s | sort > filelist.txt

for /f "tokens=*" %%a in (filelist.txt) do (
    osql  -S %server% -U %uid% -P %pwd% -d %db% -i "%%a"
)
del filelist.txt