The script provided has an IF condition which checks the DB_ID system function to see if any database exist on the SQL Server with the same name. If check is true, then the restore process is skipped.There should not be a database with the same name on the SQL Server for this script to run.
Or you can modify the script to include the REPLACE option for restoring databases. See MSDN Link: https://learn.microsoft.com/en-us/sql/t-sql/statements/restore-statements-transact-sql?view=sql-server-2017#REPLACEoption
Your script should now look like this:
IF DB_ID('Northwind') IS NULL
BEGIN //This runs if no database of the name "Northwind" exist
RESTORE DATABASE [Northwind]
FILE = N'Northwind_Data'
FROM DISK = N'C:\Program Files\Microsoft SQLServer\MSSQL10_50.SS2008\MSSQL\Backup\Northwind.bak'
WITH
FILE = 1, NOUNLOAD, STATS = 10,
MOVE N'YOUR logical name of data file as shown by RESTORE FILELISTONLY command'
TO N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SS2008\MSSQL\DATA\Northwind.mdf',
MOVE N'YOUR logical name of Log file as shown by RESTORE FILELISTONLY command'
TO N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SS2008\MSSQL\DATA\Northwind_0.LDF'
END
ELSE
BEGIN //This runs if there is a database with same name by replaceing it.
RESTORE DATABASE [Northwind]
FILE = N'Northwind_Data'
FROM DISK = N'C:\Program Files\Microsoft SQLServer\MSSQL10_50.SS2008\MSSQL\Backup\Northwind.bak'
WITH
FILE = 1, NOUNLOAD, REPLACE, STATS = 10,
MOVE N'YOUR logical name of data file as shown by RESTORE FILELISTONLY command'
TO N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SS2008\MSSQL\DATA\Northwind.mdf',
MOVE N'YOUR logical name of Log file as shown by RESTORE FILELISTONLY command'
TO N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SS2008\MSSQL\DATA\Northwind_0.LDF'
END
There are great third party tools that can perform these backups and restores and even fix corrupted database files with ease to assist you in your work. Check out Stellar Database Toolkit.
NOTE: Stack Overflow has a database administrator forum https://dba.stackexchange.com/ separate from this which is targeted for database questions like this. Post database related questions over there for a quicker and accurate answers.
Thanks and HTH.