New SQL Server 2016 Online Alter column

Over the few months i have been playing with SQL Server 2016 new features. Microsoft SQL Server 2016 introduced new alter column with ONLINE option. Let’s explore this.

  • Create a table and insert data
CREATE TABLE dbo.test_online (column_1 INT ) ;
GO
INSERT INTO dbo.test_online(column_1) values(10)
GO 
  •    Find what page has been allocated for the above operation. I have used un documented function fn_PhysLocCracker to get the information
SELECT fnph.page_id FROM dbo.test_online
 OUTER APPLY sys.fn_PhysLocCracker(%%PhysLoc%%) AS fnph;

1.png

  • Perform alter column without online option
ALTER TABLE dbo.test_online
ALTER COLUMN column_1 DECIMAL (5, 2)
--WITH (ONLINE = ON);
GO 
  • Verify what page has been allocated for the above alter column

2.png

  • You can see in the above screenshot that same page has been allocated for alter command.
  • Now, let’s Perform alter column with online option. Repeat the above steps
ALTER TABLE dbo.test_online 
 ALTER COLUMN column_1 DECIMAL (5, 2) 
 WITH (ONLINE = ON); 
GO 
  • Now verify the allocated page for the above alter command

3.png

  • You can see in the above screenshot that the new page has been allocated for alter column statement without changing the old page id. This means leaving the old page available  during the operation.

Conclusion: Online operation on alter column is really useful feature for DBA’s to perform the alter table with minimal downtime during the operation especially with table with large data.

Hope you like the post!

Happy Learning!

Cheers

Ramasankar Molleti

MSDN:LinkedIn:Twitter

 

 

 

Advertisements

About Ramasankar

My name is Ramasankar Molleti, and I have been working on sql server over 10 years, primarily focusing on Database Administration, Architect , Development and Business intelligence of sql server. I also hold various Microsoft certifications (Microsoft Certified Information Technology Professional, Microsoft Certified Technology Specialist, and Microsoft Certified Solution Associate). Disclaimer The views expressed on this website/blog are mine alone and do not reflect the views of my company. All postings on this blog are provided “AS IS” with no warranties, and confers no rights. The owner of https://sqlram.wordpress.com will not be liable for any errors or omissions in this information nor for the availability of this information. The owner will not be liable for any losses, injuries, or damages from the display or use of this information.
This entry was posted in Database Administration, SQL Server 2016, T-SQL. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s