Re: How can i ...
Posted in 1992
> I'm programming in SQL Windows on a PC. I acces an Informix Database on a > Unix machine via a gateway. > > I want to insert a record in a table with a primary key of type SERIAL and > obtain the generated value of the primary key in a variable in my > application. If I do a > > select max(primary-key-column) > from table-name > > * Laurence Humblet :-) * Merry *** Happy * > * Siemens-Nixdorf * Christmas **~**** New * Laurence, Two possible solutions to your problem. 1) You should have access to the SQLCA structure which is returned by the engine after every SQL command is executed. This structure contains a number of fields including the O/S error numbers, Informix error numbers and after an insert the value of the serial key created for the row inserted. As I don't know the tool you are using it is impossible for me to tell you how to access these variables, but check your manual in the section that deals with error returns. 2) If you have another attribute or set of attributes that can be considered an alternative (unique) key to the row use these to reselect the row after building an index on the alternative key. If no viable subset of attributes in the row can be used as an alternative key (ie the whole or majority of the row is what makes the row unique) create another attribute in your table and give it a unique value (Eg. timestamp + user code, etc) on every insert. Then, after building an index on this field, use this to reselect the row. Of course by doing this you may no longer need to use a serial attribute as the unique value can be used as the foriegn key in other tables. Cheers - Jim -------------------------------------------------------------------- Name: Jim Gordon Internet: jgordon@ssf-sys.DHL.COM Company: DHL Systems Inc Phone: (415) 358-5911 (Work) Address: 1700 S. Amphlett Blvd. (415) 882-9728 (Home) San Mateo, CA 94402 Fax: (415) 571-6429 --------------------------------------------------------------------