[ Web Proxy ]
URL:
Viewing: https://docs.cloud.google.com/sql/docs/sqlserver/export-logins [Back]  [Original]

Export SQL Server logins  |  Cloud SQL for SQL Server  |  Google Cloud Documentation Skip to main content
Google Cloud Documentation [Google Cloud Documentation]
Send feedback

Export SQL Server logins Stay organized with collections Save and categorize content based on your preferences.

This document describes how to export SQL Server logins, security identifiers (SIDs), and password hashes from a Cloud SQL for SQL Server instance by using the sp_help_revlogin stored procedure.

When you migrate databases or set up database synchronization between SQL Server instances, you must re-create user logins on the destination instance with matching SIDs and password hashes. This ensures that database users remain mapped to their corresponding server logins and retain their permissions.

Tip: We recommend exporting and re-creating logins on the destination instance before restoring your databases. Re-creating logins with matching SIDs first prevents orphaned database users. If logins or passwords change during migration, run the export again during the cutover window before redirecting application traffic.

Cloud SQL for SQL Server provides the sp_help_revlogin stored procedure in the msdb database to generate Transact-SQL (T-SQL) scripts for recreating user logins.

Before you begin

Required roles

To get the permission that you need to configure database flags, ask your administrator to grant you the following IAM roles on the project:

For more information about granting roles, see Manage access to projects, folders, and organizations.

This predefined role contains the cloudsql.instances.update permission, which is required to configure database flags.

You might also be able to get this permission with custom roles or other predefined roles.

Database permissions

Ensure that you have access to the default sqlserver SQL Server user role.

Enable the database flag

To install the sp_help_revlogin stored procedure in the msdb database, enable the cloud sql enable sp_help_revlogin database flag on your instance.

Google Cloud console

  1. In the Google Cloud console, go to the Cloud SQL Instances page.

    Go to Cloud SQL instances

  2. Click the instance name to open its Overview page.
  3. Click Edit.
  4. In the Customize your instance section, expand Flags.
  5. Click Add flag.
  6. Select cloud sql enable sp_help_revlogin from the list of available flags.
  7. Set the flag value to on.
  8. Click Save.

gcloud CLI

Enable the flag by using the gcloud CLI:

gcloud sql instances patch INSTANCE_NAME \
    --database-flags="cloud sql enable sp_help_revlogin=on"

Replace INSTANCE_NAME with the name of your Cloud SQL instance.

Note: Enabling or disabling this flag doesn't require an instance restart.

Connect using a supported client tool

The sp_help_revlogin stored procedure outputs generated CREATE LOGIN scripts using T-SQL PRINT statements (informational messages) rather than tabular result sets (SELECT statements).

Note: Cloud SQL Studio only renders tabular query results. Running `sp_help_revlogin` in Cloud SQL Studio succeeds but displays an empty results pane. To view and export the generated scripts, connect by using SQL Server Management Studio (SSMS), Visual Studio Code with the MSSQL extension, or sqlcmd.

Connect to your Cloud SQL instance by using one of the following tools:

Export logins by using sp_help_revlogin

Connect to the msdb database and run the sp_help_revlogin stored procedure.

Re-create logins on the destination instance

  1. Copy the generated CREATE LOGIN statements from the query output.
  2. Connect to your destination SQL Server instance.
  3. Execute the generated statements in a query window or by using sqlcmd.

The generated statements create the logins on the destination instance with their original SIDs, default databases, and password hashes. For more information about considerations when transferring logins across instances, see the Microsoft documentation on Transferring logins and passwords between instances of SQL Server.

Limitations and excluded logins

sp_help_revlogin automatically excludes the following types of logins from the export:

Disable the database flag

If you no longer need the stored procedure, then set the flag to off (or remove the flag from the instance):

Google Cloud console

  1. In the Google Cloud console, go to the Cloud SQL Instances page.

    Go to Cloud SQL instances

  2. Click the instance name to open its Overview page.
  3. Click Edit.
  4. In the Customize your instance section, expand Flags.
  5. Find cloud sql enable sp_help_revlogin and set its value to off (or click Delete to remove the flag).
  6. Click Save.

gcloud CLI

gcloud sql instances patch INSTANCE_NAME \
    --database-flags="cloud sql enable sp_help_revlogin=off"

When set to off or removed, Cloud SQL automatically drops dbo.sp_help_revlogin from the msdb database.

What's next

Send feedback

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-09-21 UTC.

Need to tell us more? [[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2026-09-21 UTC."],[],[]]

Web Proxy Viewer  |  New URL  |  Original Page