Mafiree logo
  • About
  • Services
  • Blogs
  • Careers
  • Products
    • orbit logo Orbit
    • streamer logo Xstreami
  • Contact
Schedule a Call
Menu
  • About
  • Services
  • Blogs
  • Careers
  • Products
    • orbit logo Orbit
    • streamer logo Xstreami
  • Contact
  • Schedule a Call
Database
Database Database Managed Services
MySQL MySQL
MySQL Consulting Services
MySQL Migration Services
MySQL Optimization & Query Tuning
MySQL Database Administration
MySQL Backup & Recovery
MySQL Security & Maintenance
MySQL Cloud Services (AWS RDS, Aurora, Google Cloud SQL, Azure)
MySQL for Ecommerce
MySQL High Availability & Replication
MongoDB MongoDB
MongoDB Consulting Services
MongoDB Migration Services
MongoDB Optimization & Query Tuning
MongoDB Database Administration
MongoDB Backup & Recovery
MongoDB Security & Maintenance
MongoDB Cloud (Atlas)
MongoDB Solutions by Industry
MongoDB High Availability & Replication
PostgreSQL PostgreSQL
PostgreSQL Consulting
PostgreSQL Migration & Upgrades
Performance Tuning & Query Optimization
PostgreSQL Administration & Managed Services
High Availability, Clustering & Replication
PostgreSQL Backup, Recovery & Disaster Planning
PostgreSQL Security, Compliance & Auditing
PostgreSQL for Analytics & Data Warehousing
PostgreSQL on Cloud & Containers
PostgreSQL Extensions & Open-Source Integrations
PostgreSQL for Every Industry
SQL Server MSSQL
MSSQL Consulting Services
MSSQL Migration Services
MSSQL Optimization & Query Tuning Services
MSSQL Database Administration Services
MSSQL Backup & Recovery Services
MSSQL High Availability & Replication Services
MSSQL Security & Compliance Services
MSSQL Performance Monitoring & Health Checks
MSSQL Solutions by Industry
Aerospike Aerospike
Aerospike Consulting Services
Aerospike Migration Services
Aerospike Performance Optimization & Tuning
Aerospike Database Administration
Aerospike Backup & Recovery
Aerospike High Availability
Aerospike Cloud & Hybrid Deployments
Aerospike for Real-Time Applications (AdTech, FinTech, Retail, IoT)
Analytics DB
Analytics DB Analytics DB Services
Clickhouse Clickhouse
ClickHouse Consulting Services
ClickHouse Migration Services
ClickHouse Optimization & Query Tuning
ClickHouse Database Administration
ClickHouse Backup & Recovery
ClickHouse Security & Maintenance
ClickHouse Cloud Services (ClickHouse Cloud, AWS, GCP, Azure)
ClickHouse Solutions by Industry
ClickHouse High Availability & Replication
TiDB TiDB
TiDB Consulting & Architecture Planning
TiDB Administration & Maintenance
TiDB Security and Privacy Maintenance
TiDB Performance & Query Optimization
TiDB Migration Services
TiDB Backup & Disaster Recovery
TiDB High Availability Solutions
TiDB Solutions by Industry
TiDB Cloud Services
ScyllaDB ScyllaDB
ScyllaDB Consulting & Architecture Planning
ScyllaDB Administration & Maintenance
ScyllaDB Security and Privacy Maintenance
ScyllaDB Performance & Query Optimization
ScyllaDB Migration Services
ScyllaDB Backup & Disaster Recovery
ScyllaDB High Availability Solutions
ScyllaDB Solutions by Industry
ScyllaDB Cloud Services
DevOps
DevOps DevOps Services
Version Control Version Control
Kubernetes Kubernetes
Infrastructure Infrastructure Management
Web Servers Web Servers
Networking
Networking Networking Services
Basic Basic
Advanced Advanced
MySQL MySQL
MongoDB MongoDB
PostgreSQL PostgreSQL
MSSQL MSSQL
Aerospike Aerospike
Clickhouse Clickhouse
TiDB TiDB
ScyllaDB ScyllaDB
Version Control Version Control
Kubernetes Kubernetes
Infrastructure Infrastructure Management
Web Servers Web Servers
Basic Basic
Advanced Advanced
MySQL Consulting Services
MySQL Migration Services
MySQL Optimization & Query Tuning
MySQL Database Administration
MySQL Backup & Recovery
MySQL Security & Maintenance
MySQL Cloud Services (AWS RDS, Aurora, Google Cloud SQL, Azure)
MySQL for Ecommerce
MySQL High Availability & Replication
MongoDB Consulting Services
MongoDB Migration Services
MongoDB Optimization & Query Tuning
MongoDB Database Administration
MongoDB Backup & Recovery
MongoDB Security & Maintenance
MongoDB Cloud (Atlas)
MongoDB Solutions by Industry
MongoDB High Availability & Replication
PostgreSQL Consulting
PostgreSQL Migration & Upgrades
Performance Tuning & Query Optimization
PostgreSQL Administration & Managed Services
High Availability, Clustering & Replication
PostgreSQL Backup, Recovery & Disaster Planning
PostgreSQL Security, Compliance & Auditing
PostgreSQL for Analytics & Data Warehousing
PostgreSQL on Cloud & Containers
PostgreSQL Extensions & Open-Source Integrations
PostgreSQL for Every Industry
MSSQL Consulting Services
MSSQL Migration Services
MSSQL Optimization & Query Tuning Services
MSSQL Database Administration Services
MSSQL Backup & Recovery Services
MSSQL High Availability & Replication Services
MSSQL Security & Compliance Services
MSSQL Performance Monitoring & Health Checks
MSSQL Solutions by Industry
Aerospike Consulting Services
Aerospike Migration Services
Aerospike Performance Optimization & Tuning
Aerospike Database Administration
Aerospike Backup & Recovery
Aerospike High Availability
Aerospike Cloud & Hybrid Deployments
Aerospike for Real-Time Applications (AdTech, FinTech, Retail, IoT)
ClickHouse Consulting Services
ClickHouse Migration Services
ClickHouse Optimization & Query Tuning
ClickHouse Database Administration
ClickHouse Backup & Recovery
ClickHouse Security & Maintenance
ClickHouse Cloud Services (ClickHouse Cloud, AWS, GCP, Azure)
ClickHouse Solutions by Industry
ClickHouse High Availability & Replication
TiDB Consulting & Architecture Planning
TiDB Administration & Maintenance
TiDB Security and Privacy Maintenance
TiDB Performance & Query Optimization
TiDB Migration Services
TiDB Backup & Disaster Recovery
TiDB High Availability Solutions
TiDB Solutions by Industry
TiDB Cloud Services
ScyllaDB Consulting & Architecture Planning
ScyllaDB Administration & Maintenance
ScyllaDB Security and Privacy Maintenance
ScyllaDB Performance & Query Optimization
ScyllaDB Migration Services
ScyllaDB Backup & Disaster Recovery
ScyllaDB High Availability Solutions
ScyllaDB Solutions by Industry
ScyllaDB Cloud Services
  1. Home
  2. > Blogs
  3. > SQL Server
  4. > Resumable Operations for ALTER TABLE Constraints in SQL Server 2022

Resumable Operations for ALTER TABLE Constraints in SQL Server 2022

Empower Your Database Management with SQL Server 2022's Resumable Operations

Chithambaresh June 26, 2023

Subscribe for email updates

Introduction:

SQL Server 2022 introduces a powerful feature called resumable operations, which enables users to perform the addition of constraints while the table remains accessible. The resumable operation for online index creation and rebuild are already supported on SQL Server 2019 and this Resumable operation feature are only supported in the SQL Server Enterprise and Developer editions.

This blog post will focus on the resumable operations feature for ALTER TABLE constraints, specifically for adding primary or unique keys. We will explore the benefits of resumable operations, its syntax, and its limitations.

Benefits of Resumable Operations:

In previous versions of SQL Server, performing online index creation or adding constraints to large tables could be time-consuming and resource-intensive. Moreover, any interruptions or failures during the execution would require restarting the operation from scratch. However, with the resumable operations feature in SQL Server 2022, users can now pause and resume operations as needed, reducing the risk of data inconsistencies and improving efficiency. This feature is a game-changer for managing large tables and minimizing downtime.

Syntax:

To declare a resumable operation for adding primary or unique key constraints to a table, you can use the following syntax:

  1. ALTER TABLE table_name ADD CONSTRAINT PK_name PRIMARY KEY CLUSTERED (column_name)                                                               WITH (ONLINE = ON, MAXDOP = 2, RESUMABLE = ON, MAX_DURATION = 240);

In the above syntax, the WITH RESUMABLE = ON clause indicates that the operation can be paused and resumed.

The optional MAX_DURATION clause allows you to specify the maximum duration, in minutes, before the operation is automatically paused.

Adjusting the MAXDOP option controls the degree of parallelism during the operation.

Let’s look at an example using T-SQL, here we are creating a Primary Key for the “Id” column on the “tblAuthors” table.

  1. ALTER TABLE tblAuthors ADD CONSTRAINT PK_name PRIMARY KEY CLUSTERED (Id)                                                                        WITH (ONLINE = ON, MAXDOP =1, RESUMABLE = ON, MAX_DURATION = 1);

In the above query we have set the Max_Duration to 1 minute. So after one minute the execution will be automatically paused and will show the message like below.

Monitoring and Managing Resumable Operations:

Once a resumable operation for adding constraints is initiated, it can be useful to monitor the progress and manage the operation. SQL Server provides several commands to facilitate this process.

  • To check the status of resumable operations, you can execute the following query:
  1. SELECT * FROM sys.index_resumable_operations;

This query provides information about the current status, progress, and other details related to ongoing resumable operations in the database.

Below is the status of the addition of the Primary key process which we have initiated.

Here you can see the process is in paused state.

  • To abort or cancel the add constraint operation, you can use the following command:
  1. ALTER INDEX ALL ON  table_name ABORT;

Executing this command will halt the operation and remove any changes made during the operation. It’s important to note that this action cannot be undone, so caution should be exercised before using the ABORT command.

  • In situations where you need to temporarily pause the add constraint operation, you can use the following command:
  1. ALTER INDEX ALL ON  table_name PAUSE;

This command will suspend the operation, allowing you to free up resources or address any immediate concerns.

  • To resume the operation, execute the following command:
  1. ALTER INDEX ALL ON  table_name RESUME;

This command will resume the add constraint operation from where it was paused, ensuring continuity and progress.

Using the above resume command, resumed the addition of Primary Key in the tblAuthors table and it was resumed from where it was paused and completed successfully.

Limitations:

It’s essential to be aware of certain limitations when utilizing resumable operations for ALTER TABLE constraints:

ONLINE Option: The ONLINE option must be set to ON to enable resumable operations for adding constraints. This option ensures that the table remains accessible during the operation.

Edition Restrictions: The ONLINE option is only available in the Enterprise and Developer editions of SQL Server. Resumable operations for ALTER TABLE constraints are supported in the Enterprise and Developer editions of SQL Server 2022. Other editions may not have access to this feature. Ensure that you have the appropriate edition to leverage resumable operations effectively.

Constraints Restrictions: Resumable operations for ALTER TABLE constraints are currently limited to primary key and unique key constraints. Foreign key constraints do not support resumable operations in SQL Server 2022.

By understanding these limitations, you can effectively plan and execute resumable operations for adding constraints in SQL Server 2022 while optimizing resource usage and minimizing downtime.

Summary:

SQL Server 2022’s resumable operations feature introduces enhanced control and flexibility for performing online operations on large tables. By allowing the addition of primary and unique key constraints through resumable operations, users can reduce downtime, minimize resource consumption, and mitigate the impact of failures or interruptions. Make the most of this powerful feature to streamline your database management processes and improve overall efficiency.

Leave a Comment

Related Blogs

How MS SQL Server Manages Data at Rest and Data in Motion

Data at Rest refers to inactive data stored in databases, while Data in Motion is actively transmitted or processed between systems in SQL Server.

  1200 views
How to Optimize SQL Server Performance: Implementing Online DDL

SQL Server 2022 added the "Wait at Low Priority" option that allows index creation and alteration to wait for resources to become available before executing.

  2657 views
Data File Splitting in SQL Server

Huge data blocks resides under single MDF file might cause a performance of the query and impact the application services. This blog help you to understand how we can the split the single MDF file into multiple data files.

  1528 views
SQL Server On Linux

SQL Server 2017 brings the best features of the Microsoft relational database engine to the enterprise Linux ecosystem, including SQL Server Agent, Azure Active Directory (Azure AD) authentication, best-in-class high availability/ disaster recovery, and unparalleled data security.

  2221 views
Achieving High Availability Using Log Shipping

Here we will get the detailed explanation of how we can achieve HA using Log Shipping.

  2798 views

Subscribe for email updates

Get in touch with us

Highlights

More than 6000 Servers Monitored

Happy Clients

Certified DBAs

24 x 7 x 365 Support

PCI

Database Services

MySQL MongoDB PostgreSQL SQL Server Aerospike Clickhouse TiDB MariaDB Columnstore

Quick Links

Careers Blog Contact Privacy Policy Disclaimer Policy

Contacts

Linkedin Mafiree Facebook Mafiree Twitter Mafiree

Nagercoil Office

Miru IT Park, Vallankumaranvillai,

Nagercoil, Tamilnadu - 629 002.

Bangalore Office

Unit 303, Vanguard Rise,

5th Main, Konena Agrahara,

Old Airport Road, Bangalore - 560 017.

Call: +91 6383016411

Email: sales@mafiree.com


Copyright © - All Rights Reserved - Mafiree