if you've gotta do it via TSQL, instead of stepping out via SMO to get it , i've spent a lot of time refining a few stored procedures to do that via TSQL.sp_GetDDLa_Latest.txt
returns a multi row table with the definitiion of any table, temp table, proc function or trigger.sp_GetDDL_Latest.txt
returns a single varchar(max) with the definitiion of any table, temp table, proc function or trigger.
both methods serve differnet functions; the first makes it REALLY readable.
the second is great when you want to stuff a CREATE TABLe definition into a field when auditing your scripts.
--help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!