How to Execute SQL Scripts using Batch file?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • raghutumma@gmail.com

    How to Execute SQL Scripts using Batch file?

    Hi,

    How can we execute SQL Scripts using Batch file???

    i think Batch file should contain Username,Passwo rd,Database and
    Scripts...
    Using that file scripts should run...

    How can i give UserName,Passwo rd,Database and all those things?

    Plz send me details how to do that...if possible with example...


    Thanx in advance,
    RR...

  • Erland Sommarskog

    #2
    Re: How to Execute SQL Scripts using Batch file?

    (raghutumma@gma il.com) writes:
    How can we execute SQL Scripts using Batch file???
    >
    i think Batch file should contain Username,Passwo rd,Database and
    Scripts...
    Using that file scripts should run...
    >
    How can i give UserName,Passwo rd,Database and all those things?
    >
    Plz send me details how to do that...if possible with example...
    From a .BAT file you can use the command-line tools OSQL or SQLCMD. They
    are largely identical, but SQLCMD has some extra bells and whistles. On
    the other hand SQLCMD only comes with SQL 2005.

    For an overview over command-line options, run OSQL -? or SQLCMD -? at
    the command line. For more details, look them up in Books Online.


    --
    Erland Sommarskog, SQL Server MVP, esquel@sommarsk og.se

    Books Online for SQL Server 2005 at

    Books Online for SQL Server 2000 at

    Comment

    • Dan Guzman

      #3
      Re: How to Execute SQL Scripts using Batch file?

      How can i give UserName,Passwo rd,Database and all those things?
      >
      Plz send me details how to do that...if possible with example...
      To expand on Erland's response, you can pass parameters on the command line
      and reference using %1 through %9. The examples below execute all the
      ".sql" scripts in the current folder using the server, database, user and
      password passed as command-line arguments.

      FOR %%f IN(*.sql) DO SQLCMD -S %1 -d %2 -U %3 -P %4 -I -i "%%f"

      FOR %%f IN(*.sql) DO OSQL -S %1 -d %2 -U %3 -P %4 -i "%%f"

      --
      Hope this helps.

      Dan Guzman
      SQL Server MVP

      <raghutumma@gma il.comwrote in message
      news:1192032042 .088785.7800@v3 g2000hsg.google groups.com...
      Hi,
      >
      How can we execute SQL Scripts using Batch file???
      >
      i think Batch file should contain Username,Passwo rd,Database and
      Scripts...
      Using that file scripts should run...
      >
      How can i give UserName,Passwo rd,Database and all those things?
      >
      Plz send me details how to do that...if possible with example...
      >
      >
      Thanx in advance,
      RR...
      >
      >

      Comment

      Working...