473,406 Members | 2,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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,Password,Database and
Scripts...
Using that file scripts should run...

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

Plz send me details how to do that...if possible with example...
Thanx in advance,
RR...

Oct 10 '07 #1
2 37620
(ra********@gmail.com) writes:
How can we execute SQL Scripts using Batch file???

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

How can i give UserName,Password,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, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Oct 10 '07 #2
How can i give UserName,Password,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

<ra********@gmail.comwrote in message
news:11********************@v3g2000hsg.googlegroup s.com...
Hi,

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

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

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

Plz send me details how to do that...if possible with example...
Thanx in advance,
RR...

Oct 12 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Bill | last post by:
I need help closing a CMD window when it is executed from Access. 1) The batch file is called from Access. 2) Access closes, 3) the batch runs a copy of the access database (creating a backup)...
1
by: John Kraft | last post by:
We have an old VB 6 web site that we are trying to update to .NET. In this project we access a old dll that wraps an active X control. For soem reason the control gives us a "catostrophic...
1
by: coosa | last post by:
Hi all, As the topic describes, I'd like to run a batch file using sql server. How do i do it? Thanks in advance
3
by: emman_54 | last post by:
Hi every one, I am trying to run a batch file using my asp.net application. I am using the Process class to run the batch file. When I run my web application, In the task manager, i could see...
5
by: benyod79 | last post by:
I'm hoping someone will be able to assist with this one. Using a scheduling program I'd like to run a batch file that runs a macro to creat e a copy of the opened database. Then, using batch again,...
1
by: RadhakrishnanR | last post by:
Hi, How to copy a file from SFTP server to local PC using Batch file. Please consider that SFTP server is installed in Linux OS NOT in Windows OS. i.e. I need Batch file script to do the above...
0
by: raghutumma | last post by:
Hi, I need help from you... I want to find SQL Servers which are available in Network and Databases in Each Server Using Batch file. If i run this Batch file it should find SQL Servers &...
0
by: gabrielk43 | last post by:
Hi to all, I have made a web service which creates a batch file in a folder in web server and tries to execute it (in a Windows Server 2003 web server). So far I have managed to create the batch...
0
by: gayatri pande | last post by:
Hi Can any one suggest a SVN command which recognizes the newly added and modified files and copy them. Thanks.
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.