How are inserts into a temp table reported in a SQL Server trace
CREATE TABLE #names (
[name] nvarchar(max)
);
INSERT INTO #names ([name])
SELECT CustomerName from CustomerInformation
Where status=3
Will the INSERT INTO #names... show up in a SQL Server trace as an INSERT to a table in tempdb or a select from CustomerInformation. Or will both show up in t开发者_StackOverflow中文版he trace?
Basically, will the trace show the statement as a insert or a select?
Depends what event you're actually looking for in the Trace:
- SQL:StmtCompleted and SP:StmtCompleted will show the statement that executed:
INSERT INTO ... SELECT FROM ...
- SQL:BatchCompleted will show the complete SQL batch (request) that executed:
CREATE TABLE ...; INSERT INTO ... SELECT FROM ...
.
Other events enabled in the Trace will show up accordingly (locks, security audits, query plans etc etc). But the gist of your question is: INSERT INTO ... SELECT ... FROM ...
is one single statement, not two statements.
Your statement will appear in the trace once, exactly as you enter it. The database associated with the statement will be the current database when the command is executed. Since you don't specify a database in the FROM clause, the current database will be the database where the CustomerInformation table resides.
精彩评论