The code I wrote was for a project I was working on to convert DateTime to DateTime2(3) in our database as part of a SQL Server 2017 upgrade project. My DF code did almost everything correctly but ultimately was not robust enough to do the job. Fortunately for me, I then went to a MS solution which worked flawlessly. If you haven't done so I highly recommend downloading this free tool from MS that is part of Visual Studio and in fact includes a free version of VS 2017. The SDDT tool will compare database schemas and generate a script to make all these changes including dropping and recreating the constraints when needed. In my case indexes had to be dropped and recreated as well. It even includes source control (we use GIT) and the changes can be committed to the repo.

https://docs.microsoft.com/en-us/sql...ql-server-2017