Monday, February 3, 2014

Ident_current function

When you insert into several tables, and when the primary key is an identity (auto number) the Ident_current function can be used to return the identity created by the insert above. In other words, if you insert a person, you will need the new personkey to insert as a foreign key in the vehicle table and the Registered customer table. Here is an example of an insert using the function.

Use Automart

Insert into Person(lastName, FirstName)
Values ('Oil', 'Caster')

Insert into Customer.vehicle (LicenseNumber, VehicleMake, VehicleYear, PersonKey)
values ('xyz123', 'Ford', '2012', ident_current('Person'))

Note that the argument for the Ident_Current function is the name of the table not the column name

No comments:

Post a Comment