Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 batch file and isql question

Author  Topic 

kkr12
Starting Member

12 Posts

Posted - 2006-02-02 : 16:57:49
Hi,
I'm trying to write a batch file which will connect to a SQLServer instance and perform the below steps.

I've a schema/db in sqlserver which will have a table with schema version information, for example schema_info with schema_version and install_date columns. So if the schema_version = 1.1 then the batch file needs to run a upgrade_schema_1.2 script which will inturn call other scripts to create/alter objects in the schema. Similarly if the schema_version is 1.0 then the batch file should first upgrade to 1.1(by calling upgrade_schema_1.1 script and then to 1.2 (by calling schema_upgrade_1.2). How can I do this in a batch file ?

Thanks in advance,
kkr12

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-02-02 : 17:01:17
You can use osql.exe to execute the scripts via the -i switch. Wrap these calls into a cmd file. Are you familiar with cmd files and osql.exe?

Tara Kizer
aka tduggan
Go to Top of Page

kkr12
Starting Member

12 Posts

Posted - 2006-02-03 : 14:06:16
Unfortunately I'm not familiar with osql utility and cmd files. Can you point me few examples on this ?

Thanks,
kkr12
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-02-03 : 15:17:56
osql.exe is a command line utility. Go to Start..Run..type in cmd and hit enter. From there, you can type osql.exe /? to see its options. It's going to be quite a bit of a learning curve though.

Here is an example osql:

osql.exe -SServer1 -E -iC:\SomeFile.Txt

And here's another one:

osql.exe -SServer1 -E
1> use MyDatabase
2> GO
1> select * from sysobjects
2> GO

...

All of the commands that you type that involve osql.exe can be wrapped into a file. Choose a file extension of cmd or bat and you'll be able to double click on it or run it in a job.

Tara Kizer
aka tduggan
Go to Top of Page

kkr12
Starting Member

12 Posts

Posted - 2006-02-06 : 10:47:22
Thanks. It is similar to isql utility right ? Thanks again.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-02-06 : 12:56:25
osql is the replacement for isql in SQL Server 2000. isql exists in 2000 still but osql is preferred.

Tara Kizer
aka tduggan
Go to Top of Page
   

- Advertisement -