The “SQL Server Management Objects” series
//Your error handling here
Finally the file is written through the TextWriter object by passing the T-SQL text constructed earlier as the function parameter. Please also be aware of the I/O exception that may occur when writing a file. Pretty easy, isn’t it?
That’s all you need to know how to enumerate tables and generate the table scripts in SQL Server using SMO. There are more another interesting and easy-to-learn articles in this SMO series. Please continue reading and enjoy!