July 18, 2012 at 6:06 am
Hi,
Is there any function which gives the table creation script.
something like below
create table <table>
(
id number,
name varchar(100))
Please help me.
I have found some approaches in google, where we need to create our function to achieve this
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=120447
http://sqlblogcasts.com/blogs/madhivanan/archive/2007/08/27/generate-sql-script.aspx
Is there any predefined function which got introduced by MS SQL server itself
Thanks in advance
July 18, 2012 at 6:09 am
Easiest way is
In SSMS, expand database, expand tables, right click table, expand script table as, expand create to, click new query editor window.
July 18, 2012 at 6:18 am
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.
Lowell
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply