I had a database backup and was trying to restore it but to a different database name than that from where it was backed up.
Let’s say you backed up MyDB and you want to restore it to MyNewDB. You can run the following TSQL:
Of course, the paths and the names of the database should be changed according to your needs.