0

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.

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes! Thank You, just tested that query and its working as intended :) That was a blazing fast replay, thank you again. As i understande if we had SQL Standard we could scheduel that script in Agent insted windows task scheduler, right?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.