T-SQL batches are collections of one or more T-SQL statements sent to SQL Server as a unit for parsing, optimization and execution. T-SQL batches end with the GO clause.

Some statements (e.g. CREATE FUNCTION, CREATE PROCEDURE, CREATE VIEW) may not be combined with others in the same batch.

Useful applications for backup and clean up

cleanup_DB.bat

SQLCMD -S .\SQLEXPRESS -i C:\iba\training\DB\cleanup_DB.sql

cleanup_DB.sql, example from ibaDatawyzer-ICC-system:

USE IBA

GO

DELETE iba_genealogic_file WHERE [_TimeStamp] < getdate() - 365

GO

DELETE iba_fingerprint_file

WHERE [_FileId] NOT IN (SELECT [_FileId] FROM iba_genealogic_file)

GO

backup_DB.bat

SQLCMD -S .\SQLEXPRESS -i C:\iba\training\DB\backup_DB.sql

backup_DB.sql:

BACKUP DATABASE IBA_TTT

TO DISK = N'C:\iba\training\DB\Backup\IBA_TTT.bak'

WITH NOFORMAT, INIT,

NAME = N'IBA_TTT Backup',

SKIP, NOREWIND, NOUNLOAD, STATS = 10