Friday, November 18, 2011

Executing all SQL files in a folder

SET dbName=RemmicomMeetingDb
SET sqlCmdCommand=sqlcmd -S . -E -i

%sqlCmdCommand% "DropAndCreateDb.sql"

FOR /F %%i IN ('dir /b /on *.sql') DO %sqlCmdCommand% %%i -d %dbName%

2 comments:

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. Just make sure they start with if they are transactional :)

    SET XACT_ABORT ON;
    GO

    BEGIN TRAN

    ...CONTENT...

    COMMIT TRAN

    ReplyDelete