Tuesday, February 14, 2012

Constraints in SQL server

i have a question about constraints in SQL server.

i have three tables:

Client
---
clientID
name
etc...

Bank
---
BankID (a virtual number, identity)
ClientID (FK: Client)
BankAccountNumber
BankName

Order
---
OrderID
ClientID
BankID

a Client an have one or more bankAccounts.. if he place an order, he can select wich bankaccount will be used to pay.

how do i have to set the constraints so that the bankAccount in Order, is allways of THAT client in order.?

Thanx...can someone give me some help? please...|||I'm not sure exactly what you're asking. It seems that if your application is going to create an order for a customer and then let the customer determine which bank account they're going to use for the order, then you have the appropriate information already. You have bank account # (or bankid) and you have customer information (clientid).

BTW, it appears that ClientID is redundant data in the Order table. Through BankID you can derive ClientID.|||It sounds like you might need a trigger. Check out this article and see if the information contained within might help:Enforcing Business Rules with Triggers.

Terri

No comments:

Post a Comment