SQL Server Performance

Creating a Batch file to execute scripts

Discussion in 'SQL Server 2005 General Developer Questions' started by apat, Feb 13, 2009.

  1. apat New Member

    Hello,
    can anyone help me with some links on how to create a batch file which will run my T-Sql scripts? Aim here is to execute the scripts by batch file and do the error trapping for exception handling during execution. Please guide.
    Thanks in advance...
  2. preethi Member

    this is what I do inside the batch file.
    sqlcmd -S <Server> -U <user> -P <password> -d <database> -i <filename> >> outputfile
    you can also include FOR command which allows you to loop through the files in a folder
  3. satya Moderator

    Updated books online is your friend in this case to refer to code examples as per Preethi's reference.
  4. apat New Member

    Thanks...
  5. FrankKalis Moderator

    When you use the
    :r full_path_to_script
    syntax, you can call another sql script from within a script.
    Just to mention it. [:)]

Share This Page