===================================================================== An iEntry.com Mailing ===================================================================== SQLProNews - Getting The Autonumber Insert ID June 19, 2007 http://www.sqlpronews.com ********************************************************************* ********************************************************************* Are you running Exchange email security tools from Symantec, McAfee, Trend, or MS-Antigen? Tired of their high (renewal) prices, hard to manage product, and/or lack of features? Upgrade to Ninja's next-generation email security, and spend half your admin time, and half your budget! Download Ninja Email Security - US/CANADA ONLY http://aj.600z.com/aj/29963/0/cc?z=1&b=29960&c=29961 ********************************************************************* ********************************************************************* Getting The Autonumber Insert ID Raymond Camden | Expert Author I love this. So I assume most folks knew about the result attribute added to cfquery in ColdFusion 7. If not - you are missing out. It returns quite a bit of good information about your query. But best of all - it was updated in ColdFusion 8. Have you ever inserted a record into a table that used an autonumber primary key? I bet you wanted a nice way to get the value of that ID? In SQL Server it is possible with a bit of extra SQL. MySQL - I'm not so sure. But as you can imagine - any solution you pick won't be very cross platform. This is the main reason I use UUIDs in my OS apps. The good news is that in ColdFusion 8, the result struct will contain a new key that contains the ID of the row you just inserted. The key is different for each support DB. ********************************************************************* ********************************************************************* Call the Domain Experts Today Find the perfect domain name & great tools for growing your business. BuyDomains.com. Business Starts Here. http://aj.600z.com/aj/30050/0/cc?z=1&b=30048&c=30049 ********************************************************************* ********************************************************************* SQL Server returns a key named IDENTITYCOL. MySQL returns GENERATED_KEY. Other database types have their own names - but lets focus on MySQL. Here is the query I used: insert into test(name) values('George Bush') Now when I dump the result, I get... (picture here): http://www.sqlpronews.com/0619img.html Pretty handy! ********************************************************************* ********************************************************************* You need to make a conference call, and you need it now. Whether you are a Fortune 500 company or a small business just getting on your feet, you need to meet when and where it’s convenient for you. Set Up Your Account For Free And Start Conferencing Today! Try ConferenceCall.com Now! http://aj.600z.com/aj/29877/0/cc?z=1&b=29408&c=29876 ********************************************************************* ********************************************************************* About the Author: Raymond Camden, ray@camdenfamily.com http://ray.camdenfamily.com Raymond Camden is Vice President of Technology for roundpeg, Inc. A long time ColdFusion user, Raymond has worked on numerous ColdFusion books and is the creator of many of the most popular ColdFusion community web sites. He is an Adobe Community Expert, user group manager, and the proud father of three little bundles of joy. ===================================================================== ===================================================================== For ad details and prices... mailto:susan@ientry.com ===================================================================== Signup for free newsletters: http://www.ientry.com/page/newsletters ===================================================================== --- SQLProNews is an iEntry.com publication --- http://www.iEntry.com iEntry, Inc. 2549 Richmond Rd Second Floor Lexington, KY 40509 ====================================================================