Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Extracting things from SQL Server
Message
De
27/02/2003 18:44:10
 
 
À
27/02/2003 17:27:33
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00759133
Message ID:
00759175
Vues:
19
This message has been marked as the solution to the initial question of the thread.
Claudio,

Here's some code that might get you started:
lcConnectionStr = "DRIVER={SQL Server};" +;
                  "SERVER=KJ4IM;"+;
                  "DATABASE=northwind;" +;
                  "UID=sa;" +;
                  "PW="

lnHandle = SQLSTRINGCONNECT(lcConnectionStr)
IF lnHandle > 0
   RetrieveSqlScripts()
   BROWSE
ENDIF

************************************************
PROCEDURE RetrieveSqlScripts
************************************************
*  Author............: Daniel Gramunt
*  Created...........: 09.01.2003 - 10:19:37 (Visual FoxPro 07.00.0000.9465)
*  Copyright.........: (c) Nokia, 2003
*) Description.......:
*  Calling Samples...:
*  Parameter List....:
*  Major change list.:
*--------------------------------------------------------------------------------------------------

LOCAL lcTempCursor, lcSql

lcTempCursor = SYS(2015)

sqlExec(lnHandle, ;
        "SELECT NAME," +;
        " XTYPE," +;
        " CRDATE," +;
        " TYPE," +;
        " REFDATE, "+;
        " CAST('' AS varchar(256) ) AS mSql"+;
        " FROM SysObjects so "+;
        " WHERE xType IN ('TR', 'P', 'FN', 'V')"+; && Triggers, SPROCs, UDFs and Views
        "  AND OBJECT_ID(so.name) IS NOT NULL" +;
        "  AND so.id IN (SELECT id FROM SysComments) ORDER BY name",;
        lcTempCursor ;
        )

*-- scan through objects and retrieve T-SQL scripts
SCAN

   WAIT WINDOW NOWAIT "Retrieving T-SQL scripts for database objects " +;
                      "Processing object '" + ALLTRIM(name) + "' "+;
                      ALLTRIM(STR(RECNO())) +;
                      " of " +;
                      ALLTRIM(STR(RECCOUNT())) +;
                      "..."

   lcSql = ""

   *-- get T-SQL script
   IF SQLEXEC(lnHandle, "EXEC sp_helptext '" + ALLTRIM(name) + "'") > 0
      *-- We may have more than one record.
      *-- Scan through SPT cursor and assemble T-SQL code
      SCAN
         *-- remove CHR(0)
         lcSql = lcSql + CHRTRAN(text , CHR(0), "") 
      ENDSCAN

   ENDIF
   
   *-- update result cursor
   REPLACE mSql WITH mSql + lcSql IN (lcTempCursor)
   
ENDSCAN
HTH
>Hi.
>
>Is there any small app available out there that reads a given DB inside SQL Server and extracts things like SPs, UDFs, Triggers, etc, and put them into individual text files somewhere?
>
>Yeah, I know that that's not a hard thing to write, but I wonder whether someone haven't came up with such a thing yet. :)
>
>TIA
Daniel
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform