Hello,
I have a DB that I created for managing banners.. I have two tables... 1 for publisher information and the other for the tracking information.
I have it set so PublisherID is the primary key for both tables...
How do I replicate it so that the IDs are always matching? OR when I create my publisher, do I just make sure when I make my inserts into the tracking table that I insert using the same ID?
I guess what I dont think I understand is what is the real reason for having these as primary keys, if there is one, will it just make indexing faster when I join the two?
Use of Primary Keys
Moderator: General Moderators
Re: Use of Primary Keys
- Start a transactionGeXus wrote: How do I replicate it so that the IDs are always matching? OR when I create my publisher, do I just make sure when I make my inserts into the tracking table that I insert using the same ID?
- Insert in the first table (generating the id is easer with auto_increment)
- Get the generated id
- Insert into the second table (use the id as a value for primary key)
- Commit transaction
I would add a foreign key constraint on the second table. And yes, an index on that foreign key will probably make it easier for the querysolver...GeXus wrote: I guess what I dont think I understand is what is the real reason for having these as primary keys, if there is one, will it just make indexing faster when I join the two?