December 6, 2010 at 2:11 pm
How to create index in table variable? The code below will get an error:
declare @order table (
member_name varchar(30),
address varchar(50)
CREATE INDEX IX_member_name
ON @order (member_name)
December 6, 2010 at 2:20 pm
http://sqlinthewild.co.za/index.php/2010/10/12/a-trio-of-table-variables/
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
December 6, 2010 at 2:52 pm
adonetok (12/6/2010)
How to create index in table variable? The code below will get an error:declare @order table (
member_name varchar(30),
address varchar(50)
CREATE INDEX IX_member_name
ON @order (member_name)
Hi
See the below samples
declare @order table (
member_name varchar(30) PRIMARY key ,
address varchar(50) )
or
declare @order table (
member_name varchar(30) UNIQUE,
address varchar(50) )
Thanks
Parthi
Thanks
Parthi
December 6, 2010 at 2:58 pm
Once create a table variable, I need to insert huge data into it. I want to create index after inserting.
December 6, 2010 at 3:00 pm
adonetok (12/6/2010)
Once create a table variable, I need to insert huge data into it. I want to create index after inserting.
Use a temp table instead.
December 6, 2010 at 3:05 pm
Then table variable(@) cant be use at this point use temp table (#) ,where you can use or modify the table
Eg:
--Create temp table
create table #temp(
number int not null,
alpha varchar(50) null
)
--- Adding some datas
if needed you can use this on condition after data has been loaded
alter table #temp
add constraint CL_temp primary key clustered(number asc)
Thanks
Parthi
Thanks
Parthi
December 6, 2010 at 3:22 pm
there was a thread alst week on how performance can be poor when you try to drop a temp table , where you created a temp table, and then add an index to it as a seperate step.
the work around was to make sure whatever column you wanted to index is either a PK or has a unique cosntraint on it in the single command CREATE TABLE definition.
Lowell
December 6, 2010 at 9:06 pm
Hope, my article will help you on this.
http://venkattechnicalblog.blogspot.com/2010/12/data-compression-in-sql-server-2008.html
Cheers,
Venkatesan Prabu .J
Thanks and Regards,
Venkatesan Prabu, 😛
My Blog:
http://venkattechnicalblog.blogspot.com/
December 6, 2010 at 10:29 pm
adonetok (12/6/2010)
Once create a table variable, I need to insert huge data into it. I want to create index after inserting.
You cannot run DDL statements on a table variable after it has been created; everything you want to do must be done as part of the DECLARE statement.
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply