473,387 Members | 3,750 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,387 software developers and data experts.

isql -- executing multiple input scripts

Hello!

We have a set of individual .SQL scripts which we would like to
execute against a MS SQL Server 2000. Is there any way to have ISQL
utility (or any other means) to execute all of them without having to
establish a separate database connection for each script:

isql -Ux -Py -Ss -i script1.sql
isql -Ux -Py -Ss -i script2.sql
isql -Ux -Py -Ss -i script3.sql
.....
isql -Ux -Py -Ss -i scriptN.sql

All scripts are in the same location, which could be made visible to
by the SQL Server itself (so either a client-based or a server-based
invokation is ok)

TIA
Jul 20 '05 #1
6 14531
al**@sinoma.com (Alex Vilner) wrote in message news:<22**************************@posting.google. com>...
Hello!

We have a set of individual .SQL scripts which we would like to
execute against a MS SQL Server 2000. Is there any way to have ISQL
utility (or any other means) to execute all of them without having to
establish a separate database connection for each script:

isql -Ux -Py -Ss -i script1.sql
isql -Ux -Py -Ss -i script2.sql
isql -Ux -Py -Ss -i script3.sql
....
isql -Ux -Py -Ss -i scriptN.sql

All scripts are in the same location, which could be made visible to
by the SQL Server itself (so either a client-based or a server-based
invokation is ok)

TIA


A minimum solution would be a batch command (untested):

for %f in (*.sql) do isql -Ux -Py -Ss -i %f

But if you write a wrapper script in a language like Perl or VBScript
you can have better control over the order the scripts are executed in
etc.

Simon
Jul 20 '05 #2
Simon, thank you for the suggestion.
This would work if scripts were independent of each other. However,
they need to be executed in the specific order, so the FOR loop will
not do it.

Oracle has a nice and easy way:
connect in SQLPlus, and then just do this:

@script1.sql
@script2.sql
@script3.sql
...
@scriptN.sql

All within the same session. Can MS SQL Server do that is the question
:)

sq*@hayes.ch (Simon Hayes) wrote in message news:<60**************************@posting.google. com>...
al**@sinoma.com (Alex Vilner) wrote in message news:<22**************************@posting.google. com>...
Hello!

We have a set of individual .SQL scripts which we would like to
execute against a MS SQL Server 2000. Is there any way to have ISQL
utility (or any other means) to execute all of them without having to
establish a separate database connection for each script:

isql -Ux -Py -Ss -i script1.sql
isql -Ux -Py -Ss -i script2.sql
isql -Ux -Py -Ss -i script3.sql
....
isql -Ux -Py -Ss -i scriptN.sql

All scripts are in the same location, which could be made visible to
by the SQL Server itself (so either a client-based or a server-based
invokation is ok)

TIA


A minimum solution would be a batch command (untested):

for %f in (*.sql) do isql -Ux -Py -Ss -i %f

But if you write a wrapper script in a language like Perl or VBScript
you can have better control over the order the scripts are executed in
etc.

Simon

Jul 20 '05 #3

"Alex Vilner" <al**@sinoma.com> wrote in message
news:22**************************@posting.google.c om...
Simon, thank you for the suggestion.
This would work if scripts were independent of each other. However,
they need to be executed in the specific order, so the FOR loop will
not do it.

Oracle has a nice and easy way:
connect in SQLPlus, and then just do this:

@script1.sql
@script2.sql
@script3.sql
...
@scriptN.sql

All within the same session. Can MS SQL Server do that is the question
:)


Yes, if you create a wrapper file which lists each script like this:

:r c:\scripts\script1.sql
:r c:\scripts\script2.sql
:r c:\scripts\script3.sql

Then execute it like this:

isql -S MyServer -d MyDatabase -E -i c:\scripts\wrapper.sql

That will load and execute each file in turn. You can also load the files
interactively, according to the documentation, although I personally only
use osql in batches, so I haven't tried it.

Simon
Jul 20 '05 #4
Have an issue with this:
1> 80> 159> 361> 415> 447> Msg 170, Level 15, State 1, Server DEVSQL01, Line 4
Line 4: Incorrect syntax near 'GO'.
Msg 170, Level 15, State 1, Server DEVSQL01, Line 7
Line 7: Incorrect syntax near 'GO'.
Msg 111, Level 15, State 1, Server DEVSQL01, Line 14
'CREATE PROCEDURE' must be the first statement in a query batch.
......

The script for procedure creation has tis general structure:
/* description */
if exists ...
drop procedure
go

SET ...
SET ...

/* comment */
create procedure ...
go

It does not seem to like the GOs inside the scripts... This is using isql.

Any other hints/suggestions?

Thanks!
"Simon Hayes" <sq*@hayes.ch> wrote in message news:<3f********@news.bluewin.ch>...
"Alex Vilner" <al**@sinoma.com> wrote in message
news:22**************************@posting.google.c om...
Simon, thank you for the suggestion.
This would work if scripts were independent of each other. However,
they need to be executed in the specific order, so the FOR loop will
not do it.

Oracle has a nice and easy way:
connect in SQLPlus, and then just do this:

@script1.sql
@script2.sql
@script3.sql
...
@scriptN.sql

All within the same session. Can MS SQL Server do that is the question
:)


Yes, if you create a wrapper file which lists each script like this:

:r c:\scripts\script1.sql
:r c:\scripts\script2.sql
:r c:\scripts\script3.sql

Then execute it like this:

isql -S MyServer -d MyDatabase -E -i c:\scripts\wrapper.sql

That will load and execute each file in turn. You can also load the files
interactively, according to the documentation, although I personally only
use osql in batches, so I haven't tried it.

Simon

Jul 20 '05 #5
Alex Vilner (al**@sinoma.com) writes:
Have an issue with this:
1> 80> 159> 361> 415> 447> Msg 170, Level 15, State 1, Server DEVSQL01,
Line 4
If you use the -n options, you will not have to look at those
80> etc.
Line 4: Incorrect syntax near 'GO'.
Msg 170, Level 15, State 1, Server DEVSQL01, Line 7
Line 7: Incorrect syntax near 'GO'.
Msg 111, Level 15, State 1, Server DEVSQL01, Line 14
'CREATE PROCEDURE' must be the first statement in a query batch.
.....


It's a bit difficult to tell what is going on, since you only posted an
outline of your script. It may help if you can post a script which
exhibits the problem.
--
Erland Sommarskog, SQL Server MVP, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #6
al**@sinoma.com (Alex Vilner) wrote in message news:<22*************************@posting.google.c om>...
Have an issue with this:
1> 80> 159> 361> 415> 447> Msg 170, Level 15, State 1, Server DEVSQL01, Line 4
Line 4: Incorrect syntax near 'GO'.
Msg 170, Level 15, State 1, Server DEVSQL01, Line 7
Line 7: Incorrect syntax near 'GO'.
Msg 111, Level 15, State 1, Server DEVSQL01, Line 14
'CREATE PROCEDURE' must be the first statement in a query batch.
.....

The script for procedure creation has tis general structure:
/* description */
if exists ...
drop procedure
go

SET ...
SET ...

/* comment */
create procedure ...
go

It does not seem to like the GOs inside the scripts... This is using isql.

Any other hints/suggestions?

Thanks!


Without seeing the whole script, it's not clear why you have
"incorrect syntax" errors, however the third error is clear - CREATE
PROC must be the first statement in a batch. You have two SET
statements, then CREATE PROC. If you use Enterprise Manager or Query
Analyzer to generate the CREATE PROC script, you'll see how it
separates these statements into separate batches:

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
if exists ...
GO
CREATE procedure dbo.SomeProc
....
GO
Simon
Jul 20 '05 #7

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

Similar topics

0
by: Nick Coghlan | last post by:
Anyone playing with the CPython interpreter's new command line switch might have noticed that it only works with top-level modules (i.e. scripts that are directly on sys.path). If the script is...
15
by: Nick Coghlan | last post by:
Python 2.4's -m command line switch only works for modules directly on sys.path. Trying to use it with modules inside packages will fail with a "Module not found" error. This PEP aims to fix that...
1
by: Jacob Grydholt Jensen | last post by:
I am trying to learn iSQL*Plus for the 1Z0-007 exam. I am having a bit of problems with the substitution variables. My understanding was that they behave as in SQL*Plus, but my experiments beg to...
2
by: RJ | last post by:
We currently send product releases to our customers, and often have to include scripts that need to be ran on the Oracle databases (also do it for SqlServer customers, but we use a different set of...
4
by: chris.dunigan | last post by:
I'm looking for an example of how to execute an existing DTS­ package from an ASP (VB)script and would appreciate any and all response. ­I don't even know if it's possible Thanks - Chuck...
4
by: Marcin Zmyslowski | last post by:
Hello everyone! I have the following problem. I`ve opened a Query Analyser and write the statement: -isql -S 'PL6XXXX' -i 'd:\SQL_Server_2000\Raport_WWW.sql' I got the following erorr...
3
by: yanakal | last post by:
Hi, I'm using isql to query data and output the same to a flat file. The isql has the following command options ' -h-1 -w500 -n -b -s"" '. In the SQL_CODE, the first two lines before the select...
1
by: Philip Bondi | last post by:
Hello to all SQL Server junkies who work with non-English characters: For people running scripts from the command line using ANSI files with special characters, it is very important to use isql...
3
by: axtens | last post by:
G'day everyone That's a space between the ticks. It's all part of a longer script but seeing as the failure occurs on line 1 if exists (select * from dbo.sysobjects where id =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.