Home > Ask the SQL Server Experts > Tony Bain Questions & Answers > Exporting T-SQL scripts from command line
Ask The SQL Server Expert: Questions & Answers
EMAIL THIS

Exporting T-SQL scripts from command line

Tony Bain EXPERT RESPONSE FROM: Tony Bain

Pose a Question
Other SQL Server Categories
Meet all SQL Server Experts
Become an Expert for this site


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


>
QUESTION POSED ON: 28 October 2003
I would like to export a bunch of T-SQL scripts to a file (each) in a command line procedure, NOT with the GUI. would like also to know when the scripts have been updated, and I thought I could do it with a trigger but these are not allowed on system tables.

>

I presume when you say scripts you are referring to stored procedures. If you don't want to script objects using the GUI the best way is to do this using the SCRIPT method of SQL-DMO. The technical reference is here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sqldmo/dmoref_m_s_0n1g.asp.

An example of this would be:

Dim server
Dim sp

SET server=CreateObject("SQLDMO.SQLServer")
server.LoginSecure=True

server.Connect "."

For Each sp in server.Databases("Northwind").StoredProcedures

 If Not sp.SystemObject then

  sp.script 68,"c:" & sp.name & "_script.sql"
 End If

Next
To determine if the SP has been changed since last time you scripted it will be a little more difficult. You will need to check and retain the values of two columns from sysobjects table. The crdate column will tell you the last time the stored procedure was dropped and recreated. The schema_ver column will change every time the stored procedure is ALTER'd. You will need to track both for each stored procedure.

For More Information


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
Tony Bain
Application not resolving username and password
Problems trying to install SQL Server on a two-node cluster on SAN
Error connecting to Web-based application
Conversion of char datatype to datetime datatype resulted in an out of range datetime value
Getting error when dropping, inserting into or truncating table with QA
Often used SP wiped out the database
Tony's SQL Server book for DBAs
Finding gaps in column of sequential numbers
Oracle SQL doesn't work in SQL Server
Recovering the database from the MDF file

SQL/Transact SQL (T-SQL)
Using DELETE and TRUNCATE TABLE statements to delete data in SQL Server
SQL language crash course (just enough to be dangerous)
Working with IntelliSense in SQL Server 2008 Management Studio
SQL Server Mailbag: Stored procedures, triggers and SSRS reports
Working with sparse columns in SQL Server 2008
Determining the source of full transaction logs in SQL Server
New GROUP BY option provides better data control in SQL Server 2008
Using the OPENROWSET function in SQL Server
Loading data files with SQL Server's BULK INSERT statement
Importing and exporting bulk data with SQL Server's bcp utility
SQL/Transact SQL (T-SQL) Research

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
ACID  (SearchSQLServer.com)
Collaboration Data Objects  (SearchSQLServer.com)
commit  (SearchSQLServer.com)
container  (SearchSQLServer.com)
DAO  (SearchSQLServer.com)
fetch  (SearchSQLServer.com)
OLE DB  (SearchSQLServer.com)
query  (SearchSQLServer.com)
SQL  (SearchSQLServer.com)
T-SQL  (SearchSQLServer.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary



Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice



SQL Solutions - SQL Database Design
HomeNewsTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersIT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2005 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts