Re: Scripting T-SQL CREATE Statements

From: Tibor Karaszi (tibor_please.no.email_karaszi_at_hotmail.nomail.com)
Date: 05/13/04


Date: Thu, 13 May 2004 16:26:03 +0200

Eric,

sp_helptext gives you the source code for most objects. Not indexes or tables, though. For these, you can use
SQLDMO, for instance. You might want to check my article at below URL which describes some options:

http://www.karaszi.com/SQLServer/info_generate_script.asp

-- 
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
"Eric Lemmon" <E_MAIL_ME_AT_ericnlisa@hotmail.com> wrote in message
news:eUijrVPOEHA.3312@tk2msftngp13.phx.gbl...
Greetings,
In a VB/C# .NET Windows application, I need to programmatically generate T-SQL script to create various
tables, stored procedures, etc., in a given database into a single text/sql file.  In essense, I want to make
a backup of user-defined SQL Server objects.  When the object in question happens to be a table, the user will
have the option to backup the table's data as well.
I am having a hard time finding the T-SQL functions and system stored procedures used to return the scripted
CREATE statements, like when you right-click an object and select Script Object to New Window as >> Create.
I am trying to get it much like the instnwnd.sql file that comes with the .NET Framework SDK v1.1.  (It is
located at C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\Samples\Setup after installing the
SDK.)  This SQL file creates the schema and inserts all data for the Northwind sample database.  It's pretty
slick!
It's fairly easy to script the tables since it can all be done within .NET code (even though it's much
slower), but the other objects--namely, stored procedures and functions--are a bit tougher to crack.  If
possible, I would like to bypass .NET code and use as many SQL Server system stored procedures/functions as
possible.
If you know of some ideas or code examples, please reply.
Many thanks,
Eric


Relevant Pages

  • Re: Generate sql script for encrypted stored procedures
    ... Nhan, you could try ... Once it is encrypted you can script it out. ... >> I encrypted my stored procedures in SQL Server 2K to deploy to the ...
    (microsoft.public.sqlserver.security)
  • Re: Strongly Type Datasets
    ... Schema for that login. ... It won't create the stored procedures. ... The SQL script it generates is based on a SQL login so the script looks ... some way or my permissions are wrong in SQL Server. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Can I search for a string in a set of stored procedures?
    ... want to go through a database full of many stored procedures to find ... my version of Sql Server Management Studio? ... Alternatively stored procedures of the database can be scripted by ... Microsoft) to script each stored procedure to individual files. ...
    (comp.databases.ms-sqlserver)
  • Re: Convert Express To Server
    ... transfer all of my tables,views, stored procedures and data from one to ... your Express database was used in a User Instance but the database files ... Use of included script samples are subject to the terms specified at ... Sql Server 2005 db? ...
    (microsoft.public.sqlserver.setup)
  • Re: Error 15401 using sp_grantlogin (not addressed by current KB articles)
    ... Restarting Windows 2000 resolved the problem for this particular account, ... confused when it sees a duplicate SID. ... > One way to get SQL Server to agree with the renamed NT ... > Preview (to ensure the script was created), ...
    (microsoft.public.sqlserver.security)