Showing posts with label customers. Show all posts
Showing posts with label customers. Show all posts

Wednesday, March 28, 2012

modeling a table with FK

I am having a problem when modeling a Foreign Key in an "Operations" table. This table holds all information on customers ′s applications and withdrawals.

Here is the structure:

CustomerID int, SourceID int, Value decimal (16,2), OperationDate datetime

Well the problem is that SourceID sometimes might be NULL depending on how the record was inserted. So its kind of cumbersome to define it as an FK, since it can be null...To get things worse, this SourceID might point to more than 1 table (depending on the CustomerType it will point to SourceA table or SourceB table)...

How should this be modeled?

What is sourceId? It sounds like you need to do a bit more normalization here and have a source table.

source
sourceId int
customerType
<other source bits>

Then your other tables like SourceA and SourceB reference this table, as well as the operations table:

create table operations
(
...I assume you have a key other than these columns,
customerId int
sourceId int null references source(sourceId)
)

Then the source will either be sourceA or sourceB depending on the customerType (assuming you are defining the source for a given customerType.) I am not sure that I am making sense, but this sounds like what I am getting from your post. If not, can you give your current table structures and a bit more about usage?

Monday, March 26, 2012

mobile phone and databases

Can you please tell me what are the risks of customers using a mobile phone to send a request of information which will be automatically responded to as an entry is made into the database.

How do I ensure that the data intergrity is maintained, as this 'Table' in the database will take in many request a day and repond based on what the customer has type in on the text message.

I did not get your point. What are you trying to do ? Sending a message to a Service, processing it in the database and sending the processed data, evtl. with a customized text back to the caller ? Data integrity should be maintained either through constraint rules (Whatever rules you have) or your logic you are trying to implement in the midtier or the database level.

HTH, Jens K. Suessmeyer.

http://www.sqlserver2005.de