| Author |
Topic |
|
CSK
Constraint Violating Yak Guru
489 Posts |
Posted - 2006-05-24 : 00:43:16
|
| Hi all,I have 100000 records to manipulate in to temp tablewhich one is best #temp table or user temp table why pleaseThanksKK |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-05-24 : 00:52:48
|
Temp table is table name prefix with #. Do you mean #temp (local) vs ##temp (global) ? And also table variable ?Why would you have so many records in temp table for processing ? KH |
 |
|
|
CSK
Constraint Violating Yak Guru
489 Posts |
Posted - 2006-05-24 : 00:57:32
|
| Yes khtan i mean #temp (local). At the time of payroll processing, they have used. I preferd local table like pay_process_tmp, because we have to put index for the table.it retrives the record fastly. if it's a #table means taking time. is it right..?ThanksKK |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2006-05-24 : 01:33:29
|
| You can create indexes on a #TempTable (and you can have a Primary Key [only] on an @TableVar - which may be sufficient?)Kristen |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-05-24 : 03:02:46
|
>>which one is best #temp table or user temp table why pleaseA temp table is the one created by user MadhivananFailing to plan is Planning to fail |
 |
|
|
CSK
Constraint Violating Yak Guru
489 Posts |
Posted - 2006-05-24 : 03:25:49
|
| No need for Primary key. Index is enough. can U give me a Sysntax for creating index for temp table..?ThanksKK |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-05-24 : 04:17:52
|
There isn't any different from creating index for your normal table. Same syntax. KH |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-05-24 : 04:20:31
|
| Read about Alter table in sql server help fileMadhivananFailing to plan is Planning to fail |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2006-05-24 : 04:29:26
|
quote: Originally posted by Kristen You can create indexes on a #TempTable (and you can have a Primary Key [only] on an @TableVar - which may be sufficient?)Kristen
You can create constraints on a table variable so can have a pk and/or unique indexes. The only thing you can't have is a non-unique index but you can get round that by having an identity and using that as the last column in a unique index.declare @a table(i int ,j int ,id int identity (1,1) ,unique (i, id))==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
CSK
Constraint Violating Yak Guru
489 Posts |
Posted - 2006-05-24 : 04:40:38
|
| thanks khtan and NRThanksKK |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-05-24 : 04:41:04
|
quote: Originally posted by nr
quote: Originally posted by Kristen You can create indexes on a #TempTable (and you can have a Primary Key [only] on an @TableVar - which may be sufficient?)Kristen
You can create constraints on a table variable so can have a pk and/or unique indexes. The only thing you can't have is a non-unique index but you can get round that by having an identity and using that as the last column in a unique index.declare @a table(i int ,j int ,id int identity (1,1) ,unique (i, id))==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy.
Now id plays as unique column?MadhivananFailing to plan is Planning to fail |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2006-05-24 : 04:49:45
|
| Yep - it has to be a constraint hence a unique index. If you have a column that isn't unique that you want to index then you can add an identity and include that in the constraint making it unique.Won't be as good an index but might help.For anything that is big enough to need this I would use a temp table instead as they have more optimisation options so would tend to perform better.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-05-24 : 07:48:31
|
| Thanks Nigel.If id has to be unique, then why cant you use this?declare @a table(i int ,j int ,id int identity (1,1) unique )MadhivananFailing to plan is Planning to fail |
 |
|
|
|