Tuesday, April 13, 2010

Trace Table SQL Server 2005

A. Using fn_trace_gettable to import rows from a trace file
The following example calls fn_trace_gettable inside the FROM clause of a SELECT...INTO statement.

USE AdventureWorks;
GO
SELECT * INTO temp_trc
FROM fn_trace_gettable('c:\temp\my_trace.trc', default);
GO


B. Using fn_trace_gettable to return a table with an IDENTITY column that can be loaded into a SQL Server table
The following example calls the function as part of a SELECT...INTO statement and returns a table with an IDENTITY column that can be loaded into the table temp_trc.


USE AdventureWorks;
GO
SELECT IDENTITY(int, 1, 1) AS RowNumber, * INTO temp_trc
FROM fn_trace_gettable('c:\temp\my_trace.trc', default);
GO



GO
/****** Object: Table [dbo].[Trace_Table2005] Script Date: 04/13/2010 10:36:52 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Trace_Table2005](
[RowNumber] [int] IDENTITY(0,1) NOT NULL,
[EventClass] [int] NULL,
[TextData] [ntext] NULL,
[ApplicationName] [nvarchar](128) NULL,
[NTUserName] [nvarchar](128) NULL,
[LoginName] [nvarchar](128) NULL,
[CPU] [int] NULL,
[Reads] [bigint] NULL,
[Writes] [bigint] NULL,
[Duration] [bigint] NULL,
[ClientProcessID] [int] NULL,
[SPID] [int] NULL,
[StartTime] [datetime] NULL,
[EndTime] [datetime] NULL,
[BinaryData] [image] NULL,
[ColumnPermissions] [int] NULL,
[DBUserName] [nvarchar](128) NULL,
[DatabaseID] [int] NULL,
[DatabaseName] [nvarchar](128) NULL,
[EventSequence] [bigint] NULL,
[EventSubClass] [int] NULL,
[HostName] [nvarchar](128) NULL,
[IsSystem] [int] NULL,
[LoginSid] [image] NULL,
[NTDomainName] [nvarchar](128) NULL,
[NestLevel] [int] NULL,
[ObjectType] [int] NULL,
[OwnerName] [nvarchar](128) NULL,
[RequestID] [int] NULL,
[RoleName] [nvarchar](128) NULL,
[ServerName] [nvarchar](128) NULL,
[SessionLoginName] [nvarchar](128) NULL,
[Success] [int] NULL,
[TargetLoginName] [nvarchar](128) NULL,
[TargetLoginSid] [image] NULL,
[TargetUserName] [nvarchar](128) NULL,
[TransactionID] [bigint] NULL,
[XactSequence] [bigint] NULL,
[BigintData1] [bigint] NULL,
[FileName] [nvarchar](128) NULL,
[GUID] [uniqueidentifier] NULL,
[IndexID] [int] NULL,
[IntegerData] [int] NULL,
[MethodName] [nvarchar](128) NULL,
[ObjectID] [int] NULL,
[ProviderName] [nvarchar](128) NULL,
[BigintData2] [bigint] NULL,
[Error] [int] NULL,
[IntegerData2] [int] NULL,
[Severity] [int] NULL,
[State] [int] NULL,
[ObjectName] [nvarchar](128) NULL,
[Type] [int] NULL,
[Offset] [int] NULL,
[PlanHandle] [image] NULL,
[SqlHandle] [image] NULL,
[LineNumber] [int] NULL,
[LinkedServerName] [nvarchar](128) NULL,
[ParentName] [nvarchar](128) NULL,
[Permissions] [bigint] NULL,
[RowCounts] [bigint] NULL,
[SourceDatabaseID] [int] NULL,
[ObjectID2] [bigint] NULL,
[Mode] [int] NULL,
[OwnerID] [int] NULL,
[Handle] [int] NULL,
PRIMARY KEY CLUSTERED
(
[RowNumber] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

No comments:

Post a Comment