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
 Transact-SQL (2000)
 calling multiple SQL scripts

Author  Topic 

gravi98
Starting Member

5 Posts

Posted - 2002-07-11 : 15:00:57
From within a SQL script, I need to call and execute several other sql scripts stored as *.sql files.

Is there a way.

I know one way is to call it using
xp_cmdshell(osql .. -i file1.sql)
..
xp_cmdshell(osql .. -i file9.sql)

Is there a better way?






setbasedisthetruepath
Used SQL Salesman

992 Posts

Posted - 2002-07-11 : 15:09:42
A DTS package, if the idea behind this nested script execution is to craft some sort of workflow.

Jonathan Boott, MCDBA
Go to Top of Page

gravi98
Starting Member

5 Posts

Posted - 2002-07-11 : 15:52:08
Thanks. But DTS package has its limits on usage. I look for a general purpose, easy to use method like " call" or "run" sort of way, you know what I mean.

I want to automate various things like creation/update of objects, grant or revoke access permissions to different users etc through scripts.

In oracle, it's pretty simple. You can run any script file as @file1.sql. I am looking for something similar.




Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-07-11 : 15:59:11
Why not just import the .sql files into stored procedures? You can make them a lot more flexible that way.

Go to Top of Page

gravi98
Starting Member

5 Posts

Posted - 2002-07-11 : 16:13:47
AS there doesn't seems to be any other easy method to call a SQL file, going by the SP way, is better and flexible.

As the statements are generic, may be all that I need to do is store them in Master DB and call from any DB against from time to time.

Thanks for the tip.


Go to Top of Page
   

- Advertisement -