---
locale: "en"
updated_at: "2025-10-27T14:22:03.464Z"
canonical: "https://www.isdecisions.com/en/userlock/docs/guides/database/migrate-another-sql-server-database"
---

# Migrate UserLock data from SQL Server to another

Detach, copy, attach in a new database.

## Introduction

In some situations, you may need to move the UserLock SQL database to a new server — for example during an infrastructure upgrade, hardware replacement, or when scaling up from SQL Express to a full SQL Server.

This guide explains how to migrate the database files and reconfigure UserLock to use the new SQL Server.

**Before you start:**

- Make sure you have **administrative rights** on both SQL Server instances.
- See [Database architecture](/userlock/docs/reference/core-concepts/database-architecture) for details about how UserLock stores its data.

## Steps

1. **Detach the database**
  - On the current SQL Server, open SQL Server Management Studio with an account that has admin rights.
  - Right-click the `UserLock` database → **Tasks ▸ Detach**.
    ![](https://a.storyblok.com/f/122374/602x619/370549c1d9/1-detach.png)
  - In the detach window, check **Drop connections** and click **OK**.
    ![](https://a.storyblok.com/f/122374/692x400/195766380e/2-detach-database.png)
2. **Copy the database files**
  - Copy the `UserLock` `.mdf` and `.ldf` files from the current server to the new one.
  ![](https://a.storyblok.com/f/122374/793x506/13cc72617f/3-copy-database-files.png)
3. **Attach the database**
  - On the new SQL Server, open SQL Server Management Studio.
  - Right-click **Databases** → **Attach…**.
  - Click **Add…**, select the copied `UserLock` file, then click **OK**.
  ![](https://a.storyblok.com/f/122374/330x327/cbe8bec860/4-attach.png)
  ![](https://a.storyblok.com/f/122374/696x474/1512396484/5-add.png)
  ![](https://a.storyblok.com/f/122374/529x459/230200b459/6-ok.png)
  ![](https://a.storyblok.com/f/122374/695x479/cf1a73d98d/7-confirm.png)
4. **Change the UserLock production database**
  - See the page [Define a production database](/userlock/docs/guides/database/define-a-production-database) to learn how to connect UserLock to the new database.

## Best practices

- **Back up before migration**: create a full backup of the UserLock database before detaching it.
- **Check integrity**: after attaching on the new server, verify that all tables and data are present.
- **Secure the new environment**: configure permissions and backups on the new SQL Server.
- **Archive the old files**: keep a copy of the old database files in case rollback is needed.
