Since you put SSMS right in the headline of your question, I'm going to suggest that you want it to be possible from there.
You can start SSMS in SQLCMD mode. This should give you much more flexibility. You can see a demo here or find more information on the Microsoft website .
For simple command line functionality, I personally would go with a Powershell script. You can add Microsoft SQL cmdlets to allow you to connect to SQL Server, or you can minimize your own SMO or work with a third-party solution, such as open source SQLPSX.
Tom h source share