Bernhard Hofmann
Bernhard Hofmann

Reputation: 10391

Can you import a SQL file into a SQL 2005/8 script?

If I have scripts in multiple files, and I would like to execute each one in a known sequence, can I simply import them into a T-SQL script and execute them, or must I run sqlcmd or similar against each file? I'm sure Oracle has a feature to import/include script content from another file (maybe with @@ ?).

I want all of the scripts to run automatically. I.e. I don't want to manually load and run each file of SQL script.

Upvotes: 1

Views: 886

Answers (4)

James C
James C

Reputation:

We have a free simple tool you can use as well - it is called Script Executor - the community edition (http://www.xsqlsoftware.com/Product/Sql_Server_Script_Executor.aspx) allows you to add individual scripts and folders containing scripts, order them and execute. There is a command line option as well in case you need to schedule the execution to run automatically.

Upvotes: 0

edosoft
edosoft

Reputation: 17271

If you want to run the scripts automatically I'd make a batch file which calls osql for each file.

-Edoode

Upvotes: 1

Nick Kavadias
Nick Kavadias

Reputation: 7338

You can concatenate the scripts into a single file. Place a GO statement at the end of each file (if it doesn't already have one) and it should be fine to run as one file instead of multiple.

Upvotes: 1

MkUltra
MkUltra

Reputation: 517

I think you can import them into a T-SQL script and execute. Better yet though, use SSMS and a maintenance plan. That way you can run the individual SQL and have some checks on success before executing the next statements.

Upvotes: 0

Related Questions