This week's book giveaway is in the Testing forum. We're giving away four copies of The Way of the Web Tester: A Beginner's Guide to Automating Tests and have Jonathan Rasmusson on-line! See this thread for details.
I am doing a project in which i am using SQL as back end. I want to write a piece of code which will make autogeneration for the field PA_NO whenever if i add the record to back end.
posted 15 years ago
Hi, Narayana. If you have no objection to sequentially assigned prime keys (1, 2, 3, etc.), then simply do a SELECT MAX() against your database table's prime key. If nothing is returned (i.e., that table has no rows), set the prime key to 1. If you get a value back from SELECT MAX(), add 1 to it to generate your next prime key. Of course, to prevent prime key duplication (a BIG no-no), you'll have to make these processes synchronized. Good luck, and I hope this helps, Art