I'm trying to insert new row into a database containing text with special characters like long dash (—). When I do this manually in my SSMS - it works okay, but when I commit the script into my version management tool (Github desktop), these symbols show up as �. In Visual Studio special characters show up normally as well. What should i do so that I can add the script properly and it could be executed potentially against any SQL Server 2016 database?
How my changes appear in Github Desktop:
It appears that the behavior is caused by the encoding type for the *.sql file to where I put my script with special characters. The file uses UTF-8 encoding, while it should be saved using UTF-8-BOM encoding to be able to display those characters correctly.
I opened a SQL script in Visual Studio containing template parameters (as they are used by SSMS usually), but Visual Studio seems to ignore them.
Some background:
In SQL Server Management Studio (SSMS), I can prepare a T-SQL script as follows and then press Ctrl+Shift+M to open a dialog, where I can enter values for the variables (syntax is: <Name, Datatype, default> as described here, and here is a more detailed description how template parameters can be used):
Example:
DECLARE #UserLastName NVARCHAR(max)='<Last name,nvarchar(max),>';
Here, the <...> bracket expressions will be replaced by the values you entered in the dialog. If you type Doe and click OK in the dialog, you will get
DECLARE #UserLastName NVARCHAR(max)='Doe';
inserted into the script afterwards. This is quite useful if you create scripts for repetitive manual tasks, because you can type the values into the dialog and get a running script for that case.
Instead of the keyboard shortcut, you can use the menu option
The issue:
I tried to do the same in Visual Studio 2017, where I have installed Microsoft SQL Server Data Tools. But the keyboard shortcut does not work there, and there seems to be no such menu option.
Do you know how to invoke this dialog in Visual Studio?
Assume that I have a query like:
INSERT INTO SomeTable(SomeCol) Values('ışç');
It succesfully inserts. But when i execute a select query for it, I get:
isc
My team mates don't have this problem. I also don't have this problem when I do this through the app I'm developing.
I guess it is about my management studio collation. I tried to find a menu to change it but I was not able to.
In the SSMS (currently running SQL Server 2008 R2), I would like to add the Description property next to the Allow Nulls property in the table designer window.
I have looked at the registry change for setting the default value of the null property as shown in this SO answer How do I set the Allow Nulls property in table designer of SSMS to be always false? However, I cannot figure out how to add the new property into the new table designer view.
I thought the the following registry entry would help.
HKEY_CURRENT_USER\Software\Microsoft\Microsoft SQL Server\100\Tools\Shell\DataProject\
SSVPropViewColumnsSQL70
SSVPropViewColumnsSQL80
I changed the registry entries of above keys from 1,2,6; to 1,2,6,9; but nothing changed in the designer.
Does anyone have any additional thoughts on this?
Here are the steps to add a property to the table designer in SQL Server Management Studio. The steps involve altering the values in registry settings.
NOTE: Please be careful while altering registry keys.
Type regedit in the Windows Start --> Run command to open the Registry Editor.
Navigate to HKEY_CURRENT_USER\Software\Microsoft\Microsoft SQL Server\100\Tools\Shell\DataProject
You might need to change the SQL Server version accordingly. I am using SQL Server 2008 R2 Express and hence the version 100. For SQL Server 2012, I found this setting under HKEY_CURRENT_USER\Software\Microsoft\SQL Server Management Studio\11.0\DataProject
Under the above mentioned registry path, look for the keys SSVPropViewColumnsSQL70 and SSVPropViewColumnsSQL80.
By default, these registry keys will have the values 1,2,6;. Section Property sequence mentioned below shows the number associated with each property. For my requirement to add Description column to the table designer, I had to change the registry key values to 1,2,6,17;
Right-click on the key and select Modify option. Change the value from 1,2,6; to 1,2,6,17;. This has to be done on both the keys SSVPropViewColumnsSQL70 and SSVPropViewColumnsSQL80
NOTE: Remember to restart SSMS between each registry change.
Property sequence:
Column Name
Data Type
Length
Precision
Scale
Allow Nulls
Default Value
Identity
Identity Seed
Identity Increment
Row GUID
Nullable
Condensed Type
Not for Replication
Formula
Collation
Description
Hope this helps someone.
For those of you looking for a .REG file to achieve this, copy/paste these lines into a text file with a .REG extension. Double click that to add it to your registry. The column numbers are listed in the answer by pithhelmet. The example below uses "14.0" meaning the version of SSMS that started being released as a standalone tool from SQL 2017 onwards. I expect that the registry path will continue to stay at 14.0 for some time yet, even with regular updates for SSMS being released.
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Microsoft\SQL Server Management Studio\14.0\DataProject]
"SSVPropViewColumnsSQL70"="1,2,6,3,7,8,17;"
"SSVPropViewColumnsSQL80"="1,2,6,3,7,8,17;"
Note that you need to have SSMS closed when you apply these changes to the registry.
For SQL Server Management Studio Version 18.x (2019):
Open Regedit and go to: "Computer\HKEY_CURRENT_USER\Software\Microsoft\SQL Server Management Studio\18.0_IsoShell\DataProject" and then Change the SSVPropViewColumnsSQL70 and SSVPropViewColumnsSQL80 Data from 1,2,6; to 1,2,6,17
For SQL-Server-Management Studio 2014 (SSMS 2014) it's a bit tricky to get the "Description" column (17):
1)
Open SSMS 2014, wait for Login-Dialog is shown. (Don't click "connect"!)
2a)
Open Regedit, goto:
"HKEY_USERS\S-1...###YOUR-WINDOWS-USER-SID###-\SOFTWARE\Microsoft\SQL Server Management Studio\12.0\DataProject"
2b)
Change the keys: SSVPropViewColumnsSQL70 and SSVPropViewColumnsSQL80 from
1,2,6; to 1,2,6,17;
3)
Now click "Connect" at the SSMS 2014 Login-Dialog.
In SQL Server Management Studio, can the Grid "Save As" be changed to write out an encoding that is Text instead of UTF-16?
When I right click a Result Grid in In SQL Server Management Studio, it allows for a Save As .CSV. Currently it saves the .CSV file encoded as UTF-16 (Unicode) but Excel does not open this format automatically (Excel prompts for a delimiter). To get around the prompt, I opened the file in SlickEdit and did a Save As "Text". Of course this is an extra step.
This answer applies if you're using Sql Server Management Studio for SQL 2005/2008.
On the "Save Results" form, the "Save" button has a small drop-down button at its right-hand end.
Click this and select "Save with Encoding". Select ANSI to get a single-byte character set.