June 10, 2005 at 12:17 pm
DECLARE @Temp TABLE
(RowId int NOT NULL IDENTITY(1, 1),
Col1 varchar(20) NULL,
PRIMARY KEY CLUSTERED (RowId) )
Does declaring a Primary Key for a table variable create a searchable Index or just a unique constraint?
June 10, 2005 at 12:41 pm
yes :
StmtText
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
DECLARE @Temp TABLE
(RowId int NOT NULL IDENTITY(1, 1),
Col1 varchar(20) NULL,
PRIMARY KEY CLUSTERED (RowId) )
Select * from @Temp where RowId = 1
(1 ligne(s) affectée(s))
StmtText
----------------------------------------------------------------------------------
|--Clustered Index Seek(OBJECT@Temp), SEEK@Temp.[RowId]=1) ORDERED FORWARD)
I know that functions with table variable have an entry in sysindexes. Maybe there's one in this case (in tempdb).. cause there doesn't seem to be one in the same db.
June 10, 2005 at 12:44 pm
Yup, there it is :
DECLARE @Temp TABLE
(RowId int NOT NULL IDENTITY(1, 1),
Col1 varchar(20) NULL,
PRIMARY KEY CLUSTERED (RowId) )
Select * from @Temp where RowId = 1
Select Object_id('Tempdb..@Temp')
--null
Select id, name, indid, status from Tempdb.dbo.SysIndexes where name like '%@temp%'
/*
id name indid status
----------- -------------------------------------------------------------------------------------------------------------------------------- ------ -----------
2050624752 PK__@Temp__7B2E3129 1 18450
*/
June 10, 2005 at 1:17 pm
I see said the blind man
Thanks Remi
June 10, 2005 at 1:21 pm
You just have to know where to look for this kind of stuff .
June 10, 2005 at 1:23 pm
BTW, I do know how to view the query plan but how do you get that in text format?
June 10, 2005 at 1:32 pm
Try this in text result mode :
SET SHOWPLAN_TEXT ON
GO
DECLARE @Temp TABLE
(RowId int NOT NULL IDENTITY(1, 1),
Col1 varchar(20) NULL,
PRIMARY KEY CLUSTERED (RowId) )
Select * from @Temp where RowId = 1
Select Object_id('Tempdb..@Temp')
--null
Select id, name, indid, status from Tempdb.dbo.SysIndexes where name like '%@temp%'
GO
SET SHOWPLAN_TEXT OFF
June 10, 2005 at 1:50 pm
Got it. Thanks again.
June 10, 2005 at 2:05 pm
I feel I must mention this one too :
SET SHOWPLAN_ALL
(gets the whole set of stats)
June 10, 2005 at 2:12 pm
I'll take a look at that also.
June 10, 2005 at 2:16 pm
Cool.
Viewing 11 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic. Login to reply