declare @CompatibilityLevelUpdate varchar(255)
set @CompatibilityLevelUpdate = "
select @CompatibilityLevelUpdate =@CompatibilityLevelUpdate +
'alter database [' + name + '] set compatibility_level =150;' + char(15)
from sys.databases
where database_id4 — exluding system databases
exec (@CompatibilityLevelUpdate)

Verify compatibility level

select name Read the rest