Hi Dawn,

This is something which should be handled by the database. In a database
where you have auto incrementing the primary keys it shouldn't be the
applications responsibility to keep an eye on that, you should be doing
simple INSERT statements and allowing the DB to do the work.

In a SQL Server database, provided you're using SQL Server Management Studio
to connect to the DB you can set the column to auto-increment by right
clicking the table in the object explorer and choosing 'modify' or 'edit'
then highlight the PK column and in the 'column properties' pane at the
bottom expand the 'identity specification' section, you'll then be able to
set the column to an identity and have it auto increment. 

Hope that helps,

Rob

-----Original Message-----
From: Dawn Sekel [mailto:dse...@ciber.com] 
Sent: 23 April 2009 17:26
To: cf-talk
Subject: CF Code to create AutoIncrement column MS SQL?


Hi:

I have a customer whose programmer has vanished and he is trying to get his 
application back on line.  I'm an intermediate CF programmer and I've
managed to 
get everything working again except for one problem.  His database is hosted
- 
and somehow, when he restored his application, the fields in his database
lost 
their autonumbering capability.  I tried creating the next number right
before 
the insert by getting the max value of the field and then adding 1 to it,
and 
that works for the most part, but occassionally, we are seeing the old
"Violation 
of PRIMARY KEY constraint 'PK_TblTestAnswers'. Cannot insert duplicate key
in 
object 'dbo.TblTestAnswers' - and I can't figure out why unless to users are

somehow hitting the same page at exactly the same time and clicking submit.
So 
the only thing I can think of to fix the problem is to recreate the
autoincrment 
key fields somehow.

Does anyone have any Coldfusion code to insert a new autoincrement key field
in 
to a MS SQL table and then remove the old one?  Or is there a way to modify
a key 
field to autoincrement? 

Thanks in advance for any advice. 



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to 
date
Get the Free Trial
http://ad.doubleclick.net/clk;207172674;29440083;f

Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:321862
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to