February 21, 2019 at 5:00 am
Hello!
If I create a index on a #temp table, without create a Primary Key, the index will work ?
It´s necessary create PK to use the index, on a #temp ?
Thank you!
February 21, 2019 at 5:19 am
JoseACJr - Thursday, February 21, 2019 5:00 AMHello!
If I create a index on a #temp table, without create a Primary Key, the index will work ?It´s necessary create PK to use the index, on a #temp ?
Thank you!
create table #temp1 (id int)
create index ix_temp1_id on #temp1 (id)
Muthukkumaran Kaliyamoorthy
https://www.sqlserverblogforum.com/
February 21, 2019 at 5:58 am
JoseACJr - Thursday, February 21, 2019 5:00 AMHello!
If I create a index on a #temp table, without create a Primary Key, the index will work ?It´s necessary create PK to use the index, on a #temp ?
Thank you!
Yes, you don't need a primary key.
It's no different to creating an index on a normal table.
February 21, 2019 at 10:55 am
You can, but you shouldn't. If you're creating only one index on a temp table, make it a clustered index not a non-clus index; the key columns don't have to qualify to be "primary key", i.e., there can be dup values and/or null values in clus index columns.
SQL DBA,SQL Server MVP(07, 08, 09) "Money can't buy you happiness." Maybe so, but it can make your unhappiness a LOT more comfortable!
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply