MS SQL Server
  Home arrow MS SQL Server arrow Scripts and Transactions in Transact-SQL
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Actuate Whitepapers 
Moblin 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MS SQL SERVER

Scripts and Transactions in Transact-SQL
By: McGraw-Hill/Osborne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 4
    2006-08-17

    Table of Contents:
  • Scripts and Transactions in Transact-SQL
  • Transactions
  • Explicit and Implicit Transactions
  • Transaction Processing Architecture
  • Nested Transactions

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Scripts and Transactions in Transact-SQL


    (Page 1 of 5 )

    Last week, we discussed batches in relation to Transact-SQL statements. This week, we touch on scripting and begin our examination of transactions. This article, the second of a three-part series, is excerpted from chapter five of the book Microsoft SQL Server 2005 Stored Procedure Programming in T-SQL and .NET, written by Dejan Sunderic (McGraw-Hill/Osborne, 2006; ISBN: 0072262281).

    Scripts

    A script is usually defined as a collection of Transact-SQL statements (in one or more batches) in the form of an external file. Client tools, such as Management Studio and SQLCMD, usually have support for managing script files.

    Scripts are usually stored in plain text files with a .sql extension. This makes them manageable from any text editor as well as from many sophisticated tools, such as the Microsoft application for code control, Visual SourceSafe.

    Management Studio has the basic script management features as any text editor, such as File | Open, Save, and some advanced features to generate scripts of database objects or to manage scripts as a part of project and solution files. SQLCMD is a command line utility that allows the user to specify script files with code to be executed against the server.

    Database Scripting

    One of the most exciting features in Management Studio is the ability to perform reverse engineering on the database without the need for external tools. The result of this process is a script that contains DDL statements, which can be used to re-create the database objects included in the script. This script can be used to

    • Explore user and system database objects
    • Back up source code
    • Establish a source control process
    • Transfer the complete database (or just some objects) to another server (and/or another database)

    The process of database scripting is very simple:

    1. Open a context-sensitive menu of a database in Management Studio.
    2. Select Tasks | Generate Scripts and the program will open the Generate SQL Server Scripts Wizard (see Figure 5-2).
    3. On the next screen the wizard will prompt you to select the database that you want to script. 
    4. If you select Script All Objects in the Selected Database checkbox, you will be able to click Finish and complete the process.
    5. If you leave the checkbox unmarked, the wizard will prompt you to choose script options (see Figure 5-3). 


      Figure 5-2.  Generate SQL Server Scripts Wizard
    6. Carefully browse the values in this dialog box. It is likely that you want to change some defaults. For example, you probably want to include indexes and object-level permissions.
    7. The wizard then prompts you to choose the major object types that you want to script.


      Figure 5-3.  Script options
    8. If you choose, for example, tables, the stored procedures program will prompt you to select which tables and stored procedures you want to script.
    9. In the Output Option window you have to choose whether scripts will be sent to a file (using Unicode or the ANSI character set), the Clipboard, or a Query window.

      TIP



      If you want to be able to open a script file from regular editors (that do not support Unicode) such as Notepad, you should select ANSI as your file format.
    10. You can now click Finish to start the process (or Next to see a summary of specified options).
    11. The wizard will display progress in the Generate Script Progress window (see Figure 5-4). After it’s done, you can click the Filter and Report buttons to manipulate the status of individual actions.

    TIP


    Use database scripting to explore the sample database associated with this book and the sample and system databases published with SQL Server. Exploration of other styles and methods in coding will help you to gain knowledge and build experience.


    Figure 5-4.
      Generate Script Progress window

    More MS SQL Server Articles
    More By McGraw-Hill/Osborne


       · This article is an excerpt from the book "Microsoft SQL Server 2005 Stored Procedure...
     

    Buy this book now. This article is excerpted from chapter five of the book Microsoft SQL Server 2005 Stored Procedure Programming in T-SQL and .NET, written by Dejan Sunderic (McGraw-Hill/Osborne, 2006; ISBN: 0072262281). Buy this book now.

    MS SQL SERVER ARTICLES

    - Completing the Introduction to Transact-SQL
    - A Brief Introduction to Transact-SQL
    - Lookups and Blocking Bad Data
    - Field Validation Rules for Blocking Bad Data
    - Using Masks to Block Bad Data
    - Blocking Bad Data
    - Using @@ROWCOUNT and TABLE Variables for Dat...
    - How to Use Variables, IF and CASE in Databas...
    - Creating Important Aspects of Notification S...
    - Working wth Variables in Database Interactio...
    - Delving Deeper into Notification Services
    - Notification Services
    - Building a Multi-table Report with SQL 2005 ...
    - A Secure Way of Building Connection Strings
    - Transferring a Database Using the SSIS Desig...




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway