Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Validations

Author  Topic 

aidmondo
Starting Member

23 Posts

Posted - 2012-05-18 : 08:44:09
Create table Events(
EventID int Primary Key Identity,
EventName Varchar(30) not null,
StartDate datetime not null,
EndDate datetime not null,
NoOfPeople int not null
)

Create table EventType(
EventTypeID int Primary Key,
Description Varchar(50)
ChargePerPerson money
)

Create table Payments(
PaymentID int Primary Key,
EventID int Foreign Key References Events(EventID),
PaymentDate datetime not null,
PaymentAmount
)

Now the following validations are to be performed on the Payments Table.
1. Payment date should be less than or equal to the StartDate of the Event.(StartDate in the Events table)
2. PaymentAmount = ChargePerPerson * NoOfPeople (chargePerPerson in EventType table and NoOfPeople in Events table)

Can this be done in the course of creating the tables? If yes help.





aidmondo

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2012-05-18 : 10:13:17
You can put constraints on the tables, or have calculated columns. Books Online (Help) will tell you how to do this.









How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

For ultra basic questions, follow these links.
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page
   

- Advertisement -