Thursday, March 22, 2012

Can I create index on table variables?

I was not able to find any document on how to create
index on table variables. Please let me know if you are
able to do so.
Thanks,
RachanFrom http://www.aspfaq.com/2475:
You cannot explicitly add an index to a table variable, however you can
create a system index through a PRIMARY KEY CONSTRAINT, and you can add as
many indexes via UNIQUE CONSTRAINTs as you like. What the optimizer does
with them is another story. <G>
--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
"Rachan Terrell" <web24by7@.hotmail.com> wrote in message
news:021601c3af95$66dc5710$a301280a@.phx.gbl...
> I was not able to find any document on how to create
> index on table variables. Please let me know if you are
> able to do so.
> Thanks,
> Rachan|||This is a multi-part message in MIME format.
--=_NextPart_000_0147_01C3AF6C.A83E9BB0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
You're not allowed to run CREATE INDEX against a table variable. However,
you can declare the variable with primary key and unique constraints:
declare @.MyTable table
(
id int primary key
, x char (1) not null
, z int not null unique
)
--
Tom
---
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinnaclepublishing.com/sql
"Rachan Terrell" <web24by7@.hotmail.com> wrote in message
news:021601c3af95$66dc5710$a301280a@.phx.gbl...
I was not able to find any document on how to create
index on table variables. Please let me know if you are
able to do so.
Thanks,
Rachan
--=_NextPart_000_0147_01C3AF6C.A83E9BB0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
&

You're not allowed to run CREATE INDEX =against a table variable. However, you can declare the variable with primary =key and unique constraints:
declare @.MyTable =table
(
=id int primary key
, =x char (1) not null
, =z int not null =unique
)
-- Tom
---T=homas A. Moreau, BSc, PhD, MCSE, MCDBASQL Server MVPColumnist, SQL =Server ProfessionalToronto, ON Canadahttp://www.pinnaclepublishing.com/sql">www.pinnaclepublishing.com=/sql
"Rachan Terrell" wrote =in message news:021601c3af95$66=dc5710$a301280a@.phx.gbl...I was not able to find any document on how to create index on table variables. Please let me know if you are able to do so.Thanks,Rachan

--=_NextPart_000_0147_01C3AF6C.A83E9BB0--|||Rachan,
Take a look at BOL for "table variable". You will see that you can indeed
create keys on table variables.
J.R.
Largo SQL Tools
The Finest Collection of SQL Tools Available
http://www.largosqltools.com
"Rachan Terrell" <web24by7@.hotmail.com> wrote in message
news:021601c3af95$66dc5710$a301280a@.phx.gbl...
> I was not able to find any document on how to create
> index on table variables. Please let me know if you are
> able to do so.
> Thanks,
> Rachan|||All,
Thanks so much for all your helps.
Take Care,
Rachan
>--Original Message--
>Rachan,
>Take a look at BOL for "table variable". You will see
that you can indeed
>create keys on table variables.
>J.R.
>Largo SQL Tools
>The Finest Collection of SQL Tools Available
>http://www.largosqltools.com
>"Rachan Terrell" <web24by7@.hotmail.com> wrote in message
>news:021601c3af95$66dc5710$a301280a@.phx.gbl...
>> I was not able to find any document on how to create
>> index on table variables. Please let me know if you
are
>> able to do so.
>> Thanks,
>> Rachan
>
>.
>

No comments:

Post a Comment