SQL server automatically generates batch execution of SQL scripts

Source: Internet
Author: User

Scenario:

The DBA exported all the creation scripts for storage, functions, and other objects to me, with thousands of files.

Now, how do I import these object creation scripts to another database?

Manual execution is obviously not realistic.

Therefore, a batch is manually written to form a. SQL script for all the files. Finally, the. SQL script generated by @ is imported to the target database.

OS: WINDOWS xp

The script content is as follows:

@ Echo offif exist list. SQL del list. SQL/q: inputclsset input =: set/p input = enter the path to be judged: set "input = % input:" = % ":: the above sentence is used to determine whether quotation marks exist in % input %. If yes, the quotation marks are removed. If "% input %" = ": "goto inputif not exist" % input % "goto inputfor/f" delims = "% I in ('dir/B/a-d/s" % input % "') do echo % ~ Fnxi> list. sqlif not exist list. SQL goto no_filestart list. sqlexit: no_fileclsecho % cur_dir % error. The list. SQL script is not generated successfully! Pause

Usage:

After saving the file as a. BAT type, double-click it to execute.

Enter the path of your script:

For example, there are the following types of files in my e-drive CRY Folder:

TEST. PRC

...

123TEST1. FNC (with subfolders 123)

...

TEST2.VW

..

After the batch processing is executed, the final list. SQL script file is as follows (the file is automatically opened in the default editor after the batch processing is executed ):

@ E: cryTEST. PRC

...

@ E: cry123TEST1. FNC

...

@ E: cryTEST2.VW

...

Open SQLPLUS to specify the user to log on to the database, and then execute: (my script file is generated on disk D)

@ D: list. SQL

In this way, all objects are automatically generated under the specified user.

---------------------------

Note: many objects generated in this way are invalid because they are not generated in order. Therefore, we recommend that you compile all invalid objects after automatic execution.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.