s

mssql how to alter column length from max to specific value without dropping the table edit button Edit

author
Murugan Andezuthu Dharmaratnam | calendar 22 January 2021 | 1795

I have a table named Purchase with several columns including PurchaseOrderNumber and PurchaseOrderLine with column data type nvarchar(max) I would like to change the data type to nvarchar(64) without dropping the table.

I am looking to change from

	[PurchaseOrderNumber] [nvarchar](max) NULL,
	[PurchaseOrderLine] [nvarchar](max) NULL,

TO 

	[PurchaseOrderNumber] [nvarchar](64) NULL,
	[PurchaseOrderLine] [nvarchar](64) NULL,

Solution

You can use the alter table TableName alter column command to do the same.

alter table TableName alter column PurchaseOrderNumber nvarchar(64)
alter table TableName alter column PurchaseOrderLine nvarchar(64)