[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 556
  • Last Modified:

Temp Table Constraint - Unique Name?

Hi
I have the attached stored procedure which creates a temp table in SQL2000 . Running the SP from VB. Unfortunately, if another user is using the VB program at the same time, I get the error:
There is already an object named 'PK_Monthly_Temp' in the database.
Could not create constraint

I take it that a constraint must have a unique name. Is there a way I can give call the constraint the user name? Or is there a better way?
Thanks
CREATE TABLE #Monthly_Temp(
	[UserName] [varchar](50) ,
	[Branch] [smallint] NOT NULL,
	[LedgerKey] [char](28)  NOT NULL,
	[Ref] [varchar](6)  NULL
	
CONSTRAINT [PK_Monthly_Temp] PRIMARY KEY NONCLUSTERED 
(	
	[Branch] ASC,
	[LedgerKey] ASC
) ON [PRIMARY]
) ON [PRIMARY]

Open in new window

0
jdhackett
Asked:
jdhackett
2 Solutions
 
dqmqCommented:
Instead of this:      
CONSTRAINT [PK_Monthly_Temp] PRIMARY KEY NONCLUSTERED

Omit the constraint name, like this:
PRIMARY KEY NONCLUSTERED
0
 
Aneesh RetnakaranDatabase AdministratorCommented:
0
 
jdhackettAuthor Commented:
Thanks. So a constraint remains, even though the temp table itself is dropped?
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now