| Author |
Topic |
|
TestEngineer
Starting Member
29 Posts |
Posted - 2006-02-16 : 09:44:03
|
| Can an identity be created in a table variable?Can joins be performed between table variables to be inserted into another table variable?Am I better of using a temporary table?(I'm working in a stored procedure here)Thanks in advance |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-02-16 : 09:48:30
|
| 1 Yes2 Yes3 It dependsMadhivananFailing to plan is Planning to fail |
 |
|
|
TestEngineer
Starting Member
29 Posts |
Posted - 2006-02-16 : 10:03:07
|
| Thanks MAdhivanan,What is the syntax for creating an identity in a table variable? Thanks |
 |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2006-02-16 : 10:06:36
|
| [code]declare @tmp table (iden int identity (1,1), other varchar(100))insert into @tmp values ('blah')select * from @tmp[/code] |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2006-02-16 : 10:08:00
|
[code]SET NOCOUNT ONDECLARE @MyTableVar TABLE( MyID int IDENTITY(1,1) NOT NULL, MyOtherCol varchar(10), PRIMARY KEY ( MyID ))INSERT INTO @MyTableVar (MyOtherCol) VALUES ('FOO')INSERT INTO @MyTableVar (MyOtherCol) VALUES ('BAR')SELECT * FROM @MyTableVar[/code] Kristen |
 |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2006-02-16 : 10:16:09
|
Kristen, you're slacking.. |
 |
|
|
TestEngineer
Starting Member
29 Posts |
Posted - 2006-02-16 : 10:21:35
|
| Thanks! That is exactly what I was looking for. |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2006-02-16 : 12:03:32
|
"you're slacking.. "Fully tested and debugged code though ... |
 |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2006-02-16 : 12:09:58
|
I guess, but who needs a primary key for a one record table.. |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2006-02-16 : 12:16:45
|
| Fully tested and debugged code ... therefore TWO records! |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-02-17 : 01:02:39
|
If identity becomes primary key, then the usage of SET IDENTITY_INSERT ON/OFF is denied MadhivananFailing to plan is Planning to fail |
 |
|
|
|