Bookmark Lines of Code in SQL Server Management Studio Query Editor Window

To navigate easier through many lines of code in SQL Server Management Studio (SSMS) Query Editor Window, it can be useful to bookmark some lines to which you would like to return to.

To set or remove a bookmark at the current line, press ‘CTRL+K’ followed by another ‘CTRL+K’. A small blue square will appear left of the bookmarked line:

ssms_bookmark_code

To move to the next bookmarked line of code from the current cursor location press ‘CTRL+K’ followed by CTRL+N, to move to the previous bookmarked line of code press ‘CTRL+K’ followed by ‘CTRL+P’.

To clear all bookmarks press ‘CTRL+K’ followed by ‘CTRL+L’.

By pressing ‘CTRL+K’ followed by ‘CTRL+W’, you can open a Bookmarks window:

ssms_bookmark_window

You can move the cursor to the bookmarked line by double clicking on the bookmark in the Bookmark Window.
There is an option to rename bookmarks in the Bookmark Window.

Go To Line Number in SQL Server Management Studio Query Editor Window

If you didn’t enable the option to Display Line Numbers in SQL Server Management Studio Query Editor Window, and you want to quickly go to a specific line number:

Click ‘Edit’ -> ‘Go To’:

ssms_edit_go_to

or press ‘CTRL + G’ to open ‘Go To Line’ dialog box:

ssms_go_to_line_dialog_box

Enter the number of the line that you want to go to, and click ‘OK’.

If you want to quickly go to the line in the code where you have a syntax error, double click the red error message and SQL Server Management Studio (SSMS) will take you directly to the line of the code stated in the error message:

ssms_double_click_on_error_message

Display Line Numbers in SQL Server Management Studio Query Editor Window

By default, line numbers are not shown in SQL Server Management Studio (SSMS) Query Editor Window next to the T-SQL code:

ssms_no_displayed_line_numbers

To enable or disable the display of line numbers next to the T-SQL code in Query Editor Window, go to:

Tools -> Options:

ssms_tools_options

Expand ‘Text Editor’ -> expand ‘Transact-SQL’ -> Click ‘General’ -> Select the ‘Line numbers’ check box:

ssms_option_display_line_numbers

Line numbers will be displayed next to the T-SQL code in all new Query Editor Windows in SQL Server Management Studio:

ssms_displayed_line_numbers

List all Table Columns that have Collations different than the SQL Server Database

To list all column collations for character-based columns (char, varchar, text, nchar, nvarchar, and ntext data) for all user-defined tables in a database (in this example we will use AdventureWorks database) that have different collation than the Database collation, run this query:

USE AdventureWorks
GO
DECLARE @DB_Name VARCHAR(50)
SET @DB_Name=(SELECT DB_NAME())
DECLARE @DB_Collation VARCHAR(50)
SET @DB_Collation=CAST(DATABASEPROPERTYEX(@DB_Name, 'Collation') as varchar(50))
SELECT s.name as 'Schema_Name', t.name as Table_Name,
c.name AS Column_Name,
c.collation_name AS Collation,
@DB_Collation AS Database_Collation
FROM sys.schemas s
INNER JOIN sys.tables t
ON t.schema_id = s.schema_id
INNER JOIN sys.columns c
ON c.object_id = t.object_id
WHERE collation_name is not null
AND collation_name <> @DB_Collation
ORDER BY Column_Name

list_all_column_collations_different_than_database

To see how to List all Column Collations for all Tables in a SQL Server Database, read related blog post:
List all Column Collations for all Tables in a SQL Server Database

List all Column Collations for all Tables in a SQL Server Database

To list all column collations for character-based columns (char, varchar, text, nchar, nvarchar, and ntext data) for all user-defined tables in a database (in this example we will use AdventureWorks database), run this query:

USE AdventureWorks
GO
SELECT s.name as 'Schema_Name', t.name as Table_Name,
c.name AS Column_Name,
c.collation_name AS Collation
FROM sys.schemas s
INNER JOIN sys.tables t
ON t.schema_id = s.schema_id
INNER JOIN sys.columns c
ON c.object_id = t.object_id
WHERE collation_name is not null
ORDER BY Column_Name

list_all_column_collations

To see how to List all Table Columns that have Collations different than the SQL Server Database, read related blog post:
List all Table Columns that have Collations different than the SQL Server Database

List all supported SQL Server Collations and the Code Page of the Collation

To list all collations supported by the version of SQL Server that you are running, and the Non-Unicode code page of the collation, run the following query:

select name, COLLATIONPROPERTY(name, 'CodePage') as Code_Page, description
from sys.fn_HelpCollations()

list_all_collations_with_code_page

Unicode-only collations do not have associated code pages, they are specified for Unicode-only data (nchar, nvarchar, and nvarchar(max)). They cannot be set at the database or server level.
If you try to create a database with a Unicode-only collation (for example ‘Lao_100_CI_AI’), you will get the following error:

Collation ‘Lao_100_CI_AI’ is supported on Unicode data types only and cannot be set at the database or server level. (Microsoft SQL Server, Error: 453).

create_database_unicode_only_error

You can see the Code Page and Description for a specific collation:

select name, COLLATIONPROPERTY(name, 'CodePage') as Code_Page, description
from sys.fn_HelpCollations()
where name = 'Latin1_General_CS_AS'

collation_with_code_page_description

For example, you can list all collation that have a name that starts with ‘SQL_L’ and have a word ‘insensitive’ in the description:

select name, COLLATIONPROPERTY(name, 'CodePage') as Code_Page, description
from sys.fn_HelpCollations()
where Name like 'SQL_L%' and Description like '%insensitive%';

collation_with_code_page_description_specific

List Databases that have a different Collation than the SQL Server Instance

To list all databases and their collations, together with the SQL Server Instance collation, run this query:

SELECT
name as Database_Name
, DATABASEPROPERTYEX(NAME,'COLLATION') AS Database_collation
, SERVERPROPERTY('COLLATION') AS Server_Collation
FROM SYS.DATABASES

list_all_database_server_collation

To list only databases that have DIFFERENT collation that the SQL Server Instance collation, run this query:

SELECT
name as Database_Name
, DATABASEPROPERTYEX(NAME,'COLLATION') AS Database_collation
, SERVERPROPERTY('COLLATION') AS Server_Collation
FROM SYS.DATABASES
WHERE (DATABASEPROPERTYEX(NAME,'COLLATION')) <> SERVERPROPERTY('COLLATION')

list_different_database_server_collation

Find Collation of a SQL Server Instance

To find Collation of a SQL Server Instance using T-SQL run this query:

SELECT SERVERPROPERTY('COLLATION')

sql_server_instance_collation_tsql

To find Collation of a SQL Server Instance using SQL Server Management Studio (SSMS):

Right Click on a SQL Server Instance in Object Explorer and choose ‘Properties’:

sql_server_instance_collation_ssms_properties

On the General tab you can see SQL Server Instance collation:

sql_server_instance_collation_ssms_view