SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Check Constraint
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

aidmondo
Starting Member

Ghana
23 Posts

Posted - 05/28/2012 :  07:14:25  Show Profile  Reply with Quote
Create table PaymentMethods(
PaymentMethodID int Primary Key,
Description not null
)
The Descriotion is either cheque, cash or CreditCard.

Create table Payments(
PaymentID int Primary Key,
PaymentMenthodID int Constraint cfkPay Foreign Key References (#above) not null,
CreditCardNo varchar(20), CardHoldersName varchar(50),
ExpDate datetime,PaymentAmount money
)
If the descriotion is creditcard, its details in the Payments table should be entered, if not the creditcard details should be left blank.

aidmondo

Edited by - aidmondo on 05/28/2012 11:15:38

SwePeso
Patron Saint of Lost Yaks

Sweden
29156 Posts

Posted - 05/28/2012 :  07:21:28  Show Profile  Visit SwePeso's Homepage  Reply with Quote
You don't need a trigger for this. You need a CHECK CONSTRAINT.



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
48076 Posts

Posted - 05/28/2012 :  13:54:25  Show Profile  Reply with Quote
quote:
Originally posted by aidmondo

Create table PaymentMethods(
PaymentMethodID int Primary Key,
Description not null
)
The Descriotion is either cheque, cash or CreditCard.

Create table Payments(
PaymentID int Primary Key,
PaymentMenthodID int Constraint cfkPay Foreign Key References (#above) not null,
CreditCardNo varchar(20), CardHoldersName varchar(50),
ExpDate datetime,PaymentAmount money
)
If the descriotion is creditcard, its details in the Payments table should be entered, if not the creditcard details should be left blank.

aidmondo


didnt i give you similar solution here?

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=175143

why cant you apply the same here?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000