简体   繁体   English

如何在SQL Server跟踪中报告临时表中的插入

[英]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. INSERT INTO #names ...是否会在SQL Server跟踪中显示为对tempdb中的表的INSERT或来自CustomerInformation的select。 Or will both show up in the 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: 取决于您在Trace中实际查找的事件:

  • SQL:StmtCompleted and SP:StmtCompleted will show the statement that executed: INSERT INTO ... SELECT FROM ... SQL:StmtCompletedSP:StmtCompleted将显示执行的语句: INSERT INTO ... SELECT FROM ...
  • SQL:BatchCompleted will show the complete SQL batch (request) that executed: CREATE TABLE ...; INSERT INTO ... SELECT FROM ... SQL:BatchCompleted将显示执行的完整SQL批处理(请求): CREATE TABLE ...; INSERT INTO ... SELECT FROM ... CREATE TABLE ...; INSERT INTO ... SELECT FROM ... . 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. 但你的问题的主旨是: INSERT INTO ... SELECT ... FROM ...一个单一的陈述,而不是两个陈述。

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. 由于未在FROM子句中指定数据库,因此当前数据库将是CustomerInformation表所在的数据库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM