SQL Server automatically generates batches of batch execution SQL scripts

Source: Internet
Author: User
Tags goto

Scene:

The DBA gave me the creation scripts for all the storage, functions, and so on, with thousands of files.

Now you need to import these object creation scripts into another library, how do you solve them?

Manual execution is obviously not realistic.

So manually wrote a batch, all the files into one. SQL scripts, which are generated at the end of @. SQL scripts are imported into the target library.

OS Environment: WINDOWS XP

The script reads as follows:

@echo off
if exist List.sql del list.sql/q
: input
cls
set input=:
set/p input=  Please enter the path to be judged: C7/>set "Input=%input:" "=%"
:: The above sentence to determine whether there are quotes in the%input%, and then remove.
if "%input%" = = ":" Goto input
if not exist "%input%" goto input
for/f "delims="%%i in (' dir/b/a-d/S "%i nput% "') do echo @@%%~fnxi>>list.sql
if not exist list.sql goto no_file
start List.sql
exit

: No_file
cls
echo       %cur_dir% error, List.sql script not successfully generated!
Pause

Use:

Save As. BAT type file, double-click Execute.

Enter the path to your script:

As in my e-disk cry folder, there are the following types of files:

TEST. PRC

...

123test1. FNC (with subfolder 123)

...

TEST2. VW

..

After the batch process is executed, the resulting List.sql script file is as follows (the file is automatically opened with the default editor after the batch is executed):

@@e:crytest.prc

...

@@e:cry123test1.fnc

...

@@e:crytest2.vw

...

Open Sqlplus to specify that the user log on to the database and execute: (My script file is generated in D disk)

@d:list.sql

All objects are automatically generated under the specified user.

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

Note: Many of these generated objects are not valid because they are not generated sequentially, so it is recommended that you compile any invalid objects after automatic execution.

Related Article

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.