question

JanVavra avatar image
0 Votes"
JanVavra asked ·

sql server management Studio Generate scripts - programatically

Is there a way to to "generate" source of commnads of Generate Scripts dialogue? Eg. I have 200 tables but I want to export only 60 of them and I do not like to click it manually. I have a txt list of table.

If it were a tsql commnad icon like on another dialogues, it would be perfect. I would be able to findstr -v and skip tables I do not want to export...
And also customer wouldn't make a mistake by forgetting eg. Create Indexes option etc etc.

sql-server-general
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

TiborKaraszi avatar image
0 Votes"
TiborKaraszi answered ·

There's not a TSQL way to do this. In the end, the functionality exists in the SMO api, and also accessible using SSIS. And I also think that Export-DbaScript in dbatools acts as a wrapper for this SMO class. Unless you prefer SSIS or some other programming language, I'd investigate powershell first.

· 4 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

SMP - Tibor obviously means SMO.

I would agree with the advice of taking the PowerShell route.

0 Votes 0 ·

Thanks Erland! Indeed. I edit my post to have the right acronym.

0 Votes 0 ·

OK. I'll inspect the Powershell.
Or I'll make a bat file full of bcp commands and use SSMS only for generating schema sql commands.

0 Votes 0 ·

I suggest you at least spend some time investigate the powershell route. It will likely save you much time in the end and less likely to do "mistakes". Here's the URL for the DmcLet that I think might be the right one for you: https://docs.dbatools.io/#Export-DbaScript

0 Votes 0 ·