Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excute sql files from a folder

Status
Not open for further replies.

Albano

Instructor
Dec 11, 2000
221
PT
Hi,

I need to make a script that excutes to sql server 2005 all sql(SP scripts) files in a folder.

Thanks,

Albano
 
Try creating a batch file, which calls the scripts with an OSQL or SQLCMD (SQL 2005) prompt, and then run the bat file from a regular command prompt.



Catadmin - MCDBA, MCSA
"No, no. Yes. No, I tried that. Yes, both ways. No, I don't know. No again. Are there any more questions?"
-- Xena, "Been There, Done That"
 
I made de bat with thw script, but it will only read one file at the time, whow can I red all like the use of *

eg:

sqlcmd -S WSALTRANIT047\FERNANDO -d APTAMIL_CENTRAL -U sa -P 1234sa -i C:\scripts\*.sql
 
if you are still looking for the answer

FOR %f IN (c:\scripts\*.sql) DO call OSQL -S SQLSERV -d DB -U sa -P pass -i %f
if u call this from the .bat just replace % with %%
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top