Reputation: 3
To start things of am not a programmer in any regards, Im that one guy who know how to click better on computers so I was asked to check what i could do about application that was bought and set up on our company server. On the first day of a new month application stoped working and as its turned out it was the first month without post Implementation support, as i checked I notice that application is trying to write data to a database that dont exist, manually creating that particular database resolved the issue. Right now im trying to figure out the way to automate this task - what i need to achive is to create a new database with month and year implementend in its name. example: name0220. Can someone point me in a direction i need to go to script something like this? Server is on MSSQL Express 2016 on Windows Server 2012 Foundation.
Upvotes: 0
Views: 53
Reputation: 46213
Below is a SQLCMD
example with a query to create the database with the month and year embedded in the name.
SQLCMD -Q"DECLARE @sql nvarchar(MAX) = N'CREATE DATABASE [name' + FORMAT(GETDATE(), N'MMyy') + N']';EXEC sp_executesql @sql;"
SQL Server Express doesn't have the SQL Agent scheduler like other SQL Server editions so you will need to schedule a script to run monthly using Windows task scheduler or similar.
Upvotes: 2