Friday, March 30, 2012

is there a syntax t-sql for generate sql scripts.

Is there syntaxs t-sql, function or others to generate
sql script of objects (table, view, stored procedure,..)?
I know we can do manualy from right click and then click
generate all scripts ? but can we do it with programming ?
thanks.For most stored procedures (assuming they are <= 8000 characters) you can
use sp_helptext, you can also SELECT ROUTINE_DEFINITION FROM
INFORMATION_SCHEMA.ROUTINES in your script.
For tables, it's a little more complicated, especially if you have
primary/foreign keys, constraints, default values, etc. I think if you're
going about it this way: create the tables, then script them properly, you
should think about doing it the other way around. :-)
"kresna rudy kurniawan" <kresna_rk@.hotmail.com> wrote in message
news:03e901c39c3b$d15a5eb0$a401280a@.phx.gbl...
> Is there syntaxs t-sql, function or others to generate
> sql script of objects (table, view, stored procedure,..)?
> I know we can do manualy from right click and then click
> generate all scripts ? but can we do it with programming ?
> thanks.|||> generate all scripts ? but can we do it with programming ?
Your best bet is SQL-DMO. Though you can invoke SQL-DMO objects and their
Script methods via T-SQL's sp_OAxxx procedures, you are much better off
using a scripting language such as VB or Perl.
Of course, if you like to do it the hard way and like to re-invent the
wheel, you can always query the system tables and construct the scripts
entirely in T-SQL. That won't be pretty though.
--
Linchi Shea
linchi_shea@.NOSPAMml.com
"kresna rudy kurniawan" <kresna_rk@.hotmail.com> wrote in message
news:03e901c39c3b$d15a5eb0$a401280a@.phx.gbl...
> Is there syntaxs t-sql, function or others to generate
> sql script of objects (table, view, stored procedure,..)?
> I know we can do manualy from right click and then click
> generate all scripts ? but can we do it with programming ?
> thanks.

No comments:

Post a Comment