May 18, 2006 at 10:54 am
May 18, 2006 at 11:12 am
I think we need to see the table definitions; it looks to me like you have separate tables for ID, name and address;
at the very least the ID and NAME should be in the same table, and maybe the address in a separate table for a 1 to many relationship.
With some more detail, we can help you write the trigger; anything we post now is just best guess/examples, most likely the same you would get from the BOL.
Also when you say "insert a name" or "insert an address", are you really saying update the exisitng record with a new name or address? isn't that the audit you want to track?
Lowell
May 18, 2006 at 11:50 am
I have a person table with personal characteristics, and separate tables (because they can have many) for names , addresses, dates of birth, driver's licenses, and ssns. Thank you so much for responding to my post because this has been troubling me for months. I ended up removing the identity column from the audit tables because that identity value seemed to be getting passed to subsequent updates to tables with foreign keys to the trigger table.
Audit Table
Audit_Table (audit_table_sid [int] IDENTITY (1, 1) NOT NULL
[DatabaseAction] [char] (1) ,
[person_sid] [int] NULL ,
[New_IP_number] [int] NULL ,
[New_sex] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
...
[Old_IP_number] [int] NULL ,
[Old_sex] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
... [CreateDateTime] [datetime] NULL
Person Table
[person] (
[person_sid] [int] IDENTITY (1, 1) NOT NULL ,
[IP_number] [int] NULL ,
[CII_number] [char] (9) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
...
Person Address Table (with foreign key to person table)
[person_address] (
[address_sid] [int] IDENTITY (1, 1) NOT NULL ,
[person_sid] [int] NOT NULL ,
[formatted_address] [varchar] (150) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[city] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[state] [char] (2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[zip] [char] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[street_number] [char] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[direction] [char] (3) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
...
May 18, 2006 at 1:43 pm
are you reading SCOPE_IDENTITY after EACH insert?
* Noel
May 18, 2006 at 5:08 pm
The inserts to the person table and all of the inserts to the person related tables that occur after the trigger insert to the audit table happen in embedded SQL inside the application (VB 6).
May 19, 2006 at 5:20 am
Hi
Have you taken a look at
IDENT_CURRENT('Datasets')
Which will return the Identity for a table?
Mike
May 19, 2006 at 3:57 pm
I'm a little confused because I'm not looking for the scope identity or any other identity. Variables in my VB code are taking on the value of the identity column from the audit table. I don't think this is an issue of which Identity function to use.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy