[sql] Run all SQL files in a directory

General Query

save the below lines in notepad with name batch.bat and place inside the folder where all your script file are there

 for %%G in (*.sql) do sqlcmd /S servername /d databasename  -i"%%G"
    pause

EXAMPLE

for %%G in (*.sql) do sqlcmd /S NFGDDD23432 /d EMPLYEEDB -i"%%G" pause

sometime if login failed for you please use the below code with username and password

for %%G in (*.sql) do sqlcmd /S SERVERNAME /d DBNAME -U USERNAME -P PASSWORD -i"%%G"
pause

for %%G in (*.sql) do sqlcmd /S NE8148server /d EMPLYEEDB -U Scott -P tiger -i"%%G" pause

After you create the bat file inside the folder in which your Script files are there just click on the bat file your scripts will get executed

Examples related to sql

Passing multiple values for same variable in stored procedure SQL permissions for roles Generic XSLT Search and Replace template Access And/Or exclusions Pyspark: Filter dataframe based on multiple conditions Subtracting 1 day from a timestamp date PYODBC--Data source name not found and no default driver specified select rows in sql with latest date for each ID repeated multiple times ALTER TABLE DROP COLUMN failed because one or more objects access this column Create Local SQL Server database

Examples related to sql-server

Passing multiple values for same variable in stored procedure SQL permissions for roles Count the Number of Tables in a SQL Server Database Visual Studio 2017 does not have Business Intelligence Integration Services/Projects ALTER TABLE DROP COLUMN failed because one or more objects access this column Create Local SQL Server database How to create temp table using Create statement in SQL Server? SQL Query Where Date = Today Minus 7 Days How do I pass a list as a parameter in a stored procedure? SQL Server date format yyyymmdd

Examples related to batch-processing

Difference between xcopy and robocopy How to use the start command in a batch file? How to close the command line window after running a batch file? Batch file. Delete all files and folders in a directory How do you convert an entire directory with ffmpeg? Run all SQL files in a directory