Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
waterduck
Aged Yak Warrior
982 Posts |
Posted - 2009-09-30 : 03:37:48
|
[code]declare @fun table (col1 int identity(1,1), col2 char(5))declare @fun2 table (col1 int, col2 varchar(20))insert into @fun select'a' UNION SELECT'b' UNION SELECT'c' UNION SELECT'd' UNION SELECT'e'insert into @fun values('ff')insert into @fun2 select top 1 col1, 'haha' from @fun order by col1 descselect * from @funselect * from @fun2[/code]just asking...how u guys use identity field as pk/fk? Hope can help...but advise to wait pros with confirmation... |
|
|
Kabila
Starting Member
33 Posts |
Posted - 2009-09-30 : 04:11:59
|
| For Primary key declare @fun table (col1 int identity(1,1) not null PRIMARY KEY, col2 char(5)) |
 |
|
|
waterduck
Aged Yak Warrior
982 Posts |
Posted - 2009-09-30 : 04:25:28
|
erm...i mean when you at @fun2, how you get @fun1 primary key as primary key at @fun2 Hope can help...but advise to wait pros with confirmation... |
 |
|
|
sanoj_av
Posting Yak Master
118 Posts |
Posted - 2009-09-30 : 04:30:43
|
quote: Originally posted by waterduck erm...i mean when you at @fun2, how you get @fun1 primary key as primary key at @fun2 Hope can help...but advise to wait pros with confirmation...
Table Variable cannot contain Foreign keys. use persistant tables.Create Table fun(col1 int identity(1,1) primary key, col2 char(5))Create Table fun2 (col1 int references fun(Col1), col2 varchar(20))insert into fun select'a' UNION SELECT'b' UNION SELECT'c' UNION SELECT'd' UNION SELECT'e'insert into fun values('ff')insert into fun2 select top 1 col1, 'haha' from fun order by col1 descselect * from funselect * from fun2 |
 |
|
|
waterduck
Aged Yak Warrior
982 Posts |
Posted - 2009-09-30 : 04:52:18
|
woops sorry...i wanna mean that...do you guys use identity field following use the identity field as foreign key Hope can help...but advise to wait pros with confirmation... |
 |
|
|
rammohan
Posting Yak Master
212 Posts |
Posted - 2009-09-30 : 05:10:40
|
| we cannot use the identity column as foreign key to a primary key column in another table.but can use identity column as a primary key in the existing tableOne can never consent to creep,when one feels an impulse to soarRAMMOHAN |
 |
|
|
waterduck
Aged Yak Warrior
982 Posts |
Posted - 2009-09-30 : 05:33:02
|
>"< as was i thinking...thx alot for yours info Hope can help...but advise to wait pros with confirmation... |
 |
|
|
|
|
|
|
|