SSMS allows you to right-click a table and “Script Table as”->”Select to”. I thought that almost everything in SSMS was done through the SMO scripting engine, but I can’t seem to find a way to do this through SMO short of looping through columns and generating the script myself.
Is my Google-Fu weak, or are people just not using SMO for something like this? I couldn’t find any example scripts for this anywhere, but it seems like it would be a common need.
It looks like the
Script()function of a table can do that:Now
scriptArraywill contain a list of SQL commands, the first entry of the string array will beset ansi_nulls on. See this blog post.