I have used below script to shrink database. I know even if not best practice but have requirement to do shrink. Is there any way to get latest database name every time into the script to shrink. at the moment I am doing manually but need to do automatically. Please can anyone suggest.
USE [Sales_backup_2016_08_10_203001_7966467]
ALTER DATABASE [Sales_backup_2016_08_10_203001_7966467]
SET RECOVERY SIMPLE
DBCC SHRINKFILE (Sales_Data)
GO
USE [Sales_backup_2016_08_10_203001_7966467]
DBCC SHRINKFILE (Sales_Log,0)
GO
ALTER DATABASE [Sales_backup_2016_08_10_203001_7966467]
SET RECOVERY SIMPLE
DBCC SHRINKFILE (Sales_Log,0)
GO