An SQL script is simply a list of Transact-SQL statements. Any trace, trace file, or trace table can be saved as an SQL script and edited within SQL Server Profiler. The SQL script will contain all the SQL statements captured in the trace. New SQL scripts can also be created within SQL Server Profiler, allowing you to build a set of Transact-SQL statements that can be tested against Microsoft® SQL Server™. The SQL script can then be saved to a file.
SQL scripts are replayed on a single connection (single thread). To execute the statements in an SQL script against the correct database, either the script must specify the database to be used using the USE <database> Transact-SQL statement or the target database must be the default database of the user replaying the SQL script. To set a default database, use sp_defaultdb system stored procedures.
SQL scripts can be replayed one statement at a time by using single stepping, which allows you to execute each statement and then test or confirm the behavior before proceeding to the next statement. SQL Server Profiler also allows the script to be modified while you are using it, although not while the script is executing. To modify the script, simply stop execution, modify the SQL in the script, and restart execution.
Note SQL Server Query Analyzer can save SQL scripts in three formats: Unicode, ANSI, and CP 437. However, because SQL Server Profiler does not support CP 437 format, some extended characters for some fonts may not appear correctly when a file saved in CP 437 format is opened in SQL Server Profiler.
To create an SQL script
To replay an SQL script
To modify an SQL script