I have two tables defined below.
Create table tickets (id long not null,
reseller long not null,
constraint pk_lock primary key (id));
Create table ticketRegistrations (id long not null,
customer long not null,
constraint fkTicketRegistrationTicket
foreign key (id) references tickets (id) on update cascade);
The client can input tickets (hence no autoincrement for the Primary Key). Since the id is the Primary key AND FOREIGN KEY of the ticketregistrations table there is integrity constraints and all that jazz. The problem I have run into is a feature request which is to allow zero padding with the ticket id (i.e. 00070). Now integers cannot be stored with zero padding to the best of my knowledge.
What solution i have come up with is to add a ticketID varchar(8) not null column in the ticket table and use the actual id for BOTH TABLES as a surrogate key. The foreign key of the ticketregistration table would then point to the ticketid.
The question I have is regarding efficiency and speed. Previously I could add a ticket registration within the system and the database would do an integrity constraint on addition to see if a ticket with the same id is within the database. Now I have a varchar string for an id which will be indexed.
When a customer "registers a ticket" will it be easier to keep the ticketid varchar in the ticket table and use a foreign key of ticketid within the ticketregistration table (also a varchar(8))?
Or will it be easier to NOT have a ticketid varchar(8) within ticketregistrations, keep the foreign key to tickets table as the primary key of the ticketregistrations table and check first for the ticketid within the ticket table, retrieve the value, and input it into a row within ticketregistrations?
This will create an indexed varchar search on the tickets table prior to each insertion into the ticketsregistrations table.
My initial solution did not need this since referential integrity took care of the problem.
I am worried about seek times.
Thank you all for your time!
Snuggs.