|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How to generate a table script in T-SQL?Hello,
Is there a way to generate a CREATE TABLE script from an existing table in T-SQL? For stored procedures I can use sp_helptext in Query Analyzer to get the procedure definition, make changes, test and then issue the ALTER. I would like to get the table script in Query Analyzer as well. I know you can do it through the Enterprise Manager. Can it be done in Query Analyzer? Thanks, Edmund To enable the Object Browser: Tools | Object Browser | Show/hide
Within the Object Browser, highlight your desired user table, and right click | Script object to new window as | Create -- Show quoteMartin C K Poon Senior Analyst Programmer ==================================== "Edmund" <die_spambot@hatespam.com> ¦b¶l¥ó news:uOS$cAxiGHA.1640@TK2MSFTNGP02.phx.gbl ¤¤¼¶¼g... > Hello, > > Is there a way to generate a CREATE TABLE script from an existing table in > T-SQL? For stored procedures I can use sp_helptext in Query Analyzer to get > the procedure definition, make changes, test and then issue the ALTER. I > would like to get the table script in Query Analyzer as well. I know you > can do it through the Enterprise Manager. Can it be done in Query Analyzer? > > Thanks, > > Edmund > > You can instantiate the SQL DMO objects from within T-SQL using sp_OACreate
and other related stored procedures. Search the net for examples on these procedures. "Edmund" <die_spambot@hatespam.com> wrote in message Is there a way to generate a CREATE TABLE script from an existing table innews:uOS$cAxiGHA.1640@TK2MSFTNGP02.phx.gbl... Hello, T-SQL? For stored procedures I can use sp_helptext in Query Analyzer to get the procedure definition, make changes, test and then issue the ALTER. I would like to get the table script in Query Analyzer as well. I know you can do it through the Enterprise Manager. Can it be done in Query Analyzer? Thanks, Edmund Thanks, both these suggestions are great!
Show quote "Narayana Vyas Kondreddi" <answer***@hotmail.com> wrote in message news:OrpqvMxiGHA.4716@TK2MSFTNGP03.phx.gbl... > You can instantiate the SQL DMO objects from within T-SQL using > sp_OACreate > and other related stored procedures. Search the net for examples on these > procedures. > -- > HTH, > Vyas, MVP (SQL Server) > SQL Server Articles and Code Samples @ http://vyaskn.tripod.com/ > > > "Edmund" <die_spambot@hatespam.com> wrote in message > news:uOS$cAxiGHA.1640@TK2MSFTNGP02.phx.gbl... > Hello, > > Is there a way to generate a CREATE TABLE script from an existing table in > T-SQL? For stored procedures I can use sp_helptext in Query Analyzer to > get > the procedure definition, make changes, test and then issue the ALTER. I > would like to get the table script in Query Analyzer as well. I know you > can do it through the Enterprise Manager. Can it be done in Query > Analyzer? > > Thanks, > > Edmund > > > Here is an article that should provide you with some examples of how to
script out out objects: http://www.dbazine.com/sql/sql-articles/larsen4 Show quote "Edmund" wrote: > Hello, > > Is there a way to generate a CREATE TABLE script from an existing table in > T-SQL? For stored procedures I can use sp_helptext in Query Analyzer to get > the procedure definition, make changes, test and then issue the ALTER. I > would like to get the table script in Query Analyzer as well. I know you > can do it through the Enterprise Manager. Can it be done in Query Analyzer? > > Thanks, > > Edmund > > > You can also use
select * from information_schema.columns and others and just create concatenation script from field values to get your final script. + CHAR(13) + CHAR(10) , CHAR(9) can be used to format it nicely. I use this very often and can get output exactly to my liking. Show quote "Edmund" <die_spambot@hatespam.com> wrote in message news:uOS$cAxiGHA.1640@TK2MSFTNGP02.phx.gbl... > Hello, > > Is there a way to generate a CREATE TABLE script from an existing table in > T-SQL? For stored procedures I can use sp_helptext in Query Analyzer to > get the procedure definition, make changes, test and then issue the ALTER. > I would like to get the table script in Query Analyzer as well. I know > you can do it through the Enterprise Manager. Can it be done in Query > Analyzer? > > Thanks, > > Edmund > |
|||||||||||||||||||||||