SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Explicit Value error, why?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

phrankbooth
Posting Yak Master

USA
161 Posts

Posted - 01/30/2007 :  18:20:28  Show Profile  Reply with Quote
Hello,

In the SP below, I get the following error when I run it:
Explicit value must be specified for identity column in table 'Tests' when IDENTITY_INSERT is set to ON.

From what I've read of the INSERT method, it says you can add a variable value. So I don;t understand why it won't take mine.

CREATE PROC qaspAddTestRecord AS

DECLARE @aKey bigint
DECLARE @aTestSuiteId bigint

exec qaspGetNewID 'Tests', @aKey OUT

SELECT @aTestSuiteId= NewID FROM ID WHERE TableName='TestSuite'

SET IDENTITY_INSERT Tests ON

INSERT INTO Tests (TestSuiteId, TestIDInternal) VALUES (@aTestSuiteId, @aKey)

SET IDENTITY_INSERT Tests OFF
GO


--PhB

phrankbooth
Posting Yak Master

USA
161 Posts

Posted - 01/30/2007 :  18:32:02  Show Profile  Reply with Quote
Never mind, I answered my own question.

You have to tell the SP which field the Key field is, how silly of me.

--PhB
Go to Top of Page

tkizer
Almighty SQL Goddess

USA
37291 Posts

Posted - 01/30/2007 :  18:40:13  Show Profile  Visit tkizer's Homepage  Reply with Quote
What is the point of using the Identity option if you aren't going to let SQL Server manage the data for you?

Tara Kizer
Go to Top of Page

phrankbooth
Posting Yak Master

USA
161 Posts

Posted - 01/31/2007 :  13:03:58  Show Profile  Reply with Quote
I want to avoid concurrency issues. MS wrote an article saying that if you want to guarantee unique id's, do your own method.

What I have now is working quite nicely for me.

--PhB
Go to Top of Page

tkizer
Almighty SQL Goddess

USA
37291 Posts

Posted - 01/31/2007 :  13:09:54  Show Profile  Visit tkizer's Homepage  Reply with Quote
Whether or not it works for you or not doesn't make it the proper design. Identity option is guaranteed to be unique if it is set as the primary key for the table. The constraint guarantees the uniqueness.

Tara Kizer
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000