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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Primary key on table variable

Author  Topic 

Antonio
Posting Yak Master

168 Posts

Posted - 2006-03-10 : 09:48:14
Greetings!

I am struggling to create a primary key made of 4 columns in one of my declared table variables.

What is the exact syntax for doing this?

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2006-03-10 : 09:58:16
I'm not sure of the benefit you'll get from this but it's the same as a normal table...

declare @tb table
(i1 int
,i2 int
,primary key (i1,i2))

insert @tb (i1,i2)
select 1,1 union all
select 1,2
--union all select 1,2 /*generate a pk violation*/


Be One with the Optimizer
TG
Go to Top of Page

Antonio
Posting Yak Master

168 Posts

Posted - 2006-03-10 : 10:02:46
quote:
Originally posted by TG

I'm not sure of the benefit you'll get from this but it's the same as a normal table...

declare @tb table
(i1 int
,i2 int
,primary key (i1,i2))

insert @tb (i1,i2)
select 1,1 union all
select 1,2
--union all select 1,2 /*generate a pk violation*/


Be One with the Optimizer
TG



Thanks for this.
Go to Top of Page
   

- Advertisement -