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.
sql server management Studio Generate scripts - programatically
Jan Vávra
251
Reputation points
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.