最近我重新在我的笔记本电脑上安装了SSMS 2008。
当我点击“新建查询...”时,现在会提示我选择文件的编码方式,这是以前从未被要求做过的事情。
我已经在选项的文本编辑器部分将SQL关联到“带编码的SQL查询编辑器”,并重新启动了SSMS。
我该怎么做才能关联到编码方式呢?我不想每次新建查询或打开现有的sql文件都需要重新选择。
最近我重新在我的笔记本电脑上安装了SSMS 2008。
当我点击“新建查询...”时,现在会提示我选择文件的编码方式,这是以前从未被要求做过的事情。
我已经在选项的文本编辑器部分将SQL关联到“带编码的SQL查询编辑器”,并重新启动了SSMS。
我该怎么做才能关联到编码方式呢?我不想每次新建查询或打开现有的sql文件都需要重新选择。
我遇到了同样的问题。Git不会显示历史记录中的任何差异(除了“二进制文件a/x.sql和b/x.sql不同”)。因此,我单击了“工具=>选项=>环境=>国际设置”。将语言从“英语”更改为“与Microsoft Windows相同”。现在GIT DIFF运行得非常完美--正常报告版本差异!
根据其他地方给出的建议(https://feedback.azure.com/forums/908035-sql-server/suggestions/32892454-need-a-way-to-set-the-default-encoding-for-query-f),我编写了一个“命令脚本”来尝试将默认编码更改为带BOM的UTF-8。该脚本通过将UTF-8 w / BOM模板写入SQL Server程序文件树中的SQLFile.sql文件来工作。它在我的机器上曾经成功过一次,但这并不意味着它是无错误或100%安全的。请自行决定是否使用!
根据那个线程中“Microsoft”的回复:
请注意,我的计算机上找到的模板路径不同,因此我编写了脚本来查找任何一个在“Program Files”下与其匹配的文件名。看起来这是一个非常愚蠢的名字,假冒的情况应该很少发生。文件保存方式的默认设置由位于C:\ Program Files \ Microsoft SQL Server \ 90 \ Tools \ Binn \ VSShell \ Common7 \ IDE \ sqlworkbenchprojectitems \ Sql的主模板文件SQLFile.sql确定。如果您使用ANSI编码保存此文件,则后续的新查询会话将使用此编码。
@echo off
setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION || exit /b 1
if "x%1" == "xforce" (
echo Force enable. Danger Will Robinson! This means that I'm going to
echo attempt to move files and write a new file to replace them. This
echo is potentially destructive if there are any bugs in this script.
echo In particular, if there are any unrelated files with the name
echo sqlfile.sql under your Program Files directories then they'll be
echo corrupted.
echo.
echo This script is going to require elevated privileges to write to
echo Program Files. Execute the Command Prompt application as an
echo administrator to proceed ^(should be harmless to try without
echo elevation first^).
echo.
echo I RECOMMEND YOU _DO NOT_ RUN THIS SCRIPT FROM WINDOWS EXPLORER
echo BECAUSE YOU MAY HAVE A HARDER TIME READING THE OUTPUT. Start a
echo Command Prompt and run it there.
echo.
if not "x%2" == "xdontpause" (
echo Now is a good time to Ctrl+C ^(and Y^).
pause
)
) else (
echo Dry-run enabled. Pass a lone argument of "force" to go for real. 1>&2
echo Be careful running the script several times. Your template backup
echo will be overwritten and lost.
)
set paths="C:\Program Files (x86)\SQLFile.sql" "C:\Program Files\SQLFile.sql"
for /f "tokens=*" %%f in ('dir /a /b /s %paths% 2^>NUL') do @(
echo.
echo Found: %%f
if "x%1" == "xforce" (
echo Moving to: %%f.orig
echo.
echo If you ^(or anything else^) has made any changes to your template
echo then you should be able to recover your template from the backup
echo file above ^(not yet, once you continue^) ^(alternatively,
echo recover the template from the source file now^).
if not "x%2" == "xdontpause" (
pause
)
move "%%f" "%%f.orig" || exit /b 1
)
echo.
echo Writing a standard UTF-8 template with byte-order mark ^(BOM^).
echo Feel free to open this file up afterward and manually set the
echo encoding preferred. You can also replace it with your own
echo template text.
if not "x%2" == "xdontpause" (
pause
)
set ok=0
rem Read in myself, look for the __BEGIN__ marker and write
rem subsequent lines to the file.
for /f "tokens=*" %%g in (%~dpf0) do @(
if !ok! == 1 (
if "x%1" == "xforce" (
if "x%%g" == "x." (
echo.
echo.>>"%%f"|| exit /b 1
) else (
echo %%g
echo %%g>>"%%f"|| exit /b 1
)
)
) else (
if "%%g" == "__BEGIN__" (
echo.
echo Found marker. Starting write on next ^(non-empty^) line... 1>&2
echo.
set ok=1
)
)
)
)
exit /b 0
Below is the SQL template. Lines containing only a dot (.) represent
blank lines. Actual blank lines will be lost.
__BEGIN__
BEGIN TRANSACTION;
.
SET XACT_ABORT ON;
.
.
.
ROLLBACK;
--COMMIT;
之前的答案建议使用“工具”→“选项”→“环境”→“国际设置”,但是在SSMS 17.2中没有这个选项。
相反,您可以前往“文件”→“另存为...”,点击“保存”按钮上的箭头,并选择“编码方式另存为”。
我真是个白痴 - 我把关联改成了“SQL查询编辑器”,现在一切都正常了
“带编码”这一点真的应该让我想到!