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.
Author |
Topic |
Kimi86
Yak Posting Veteran
79 Posts |
Posted - 2014-04-01 : 21:31:27
|
CREATE TABLE EmployeeDetails ( EmployeeId VARCHAR(20) PRIMARY KEY, FirstName VARCHAR(20) NOT NULL, LastName VARCHAR(20) NOT NULL, IsActive BINARY NOT NULL, YearlyPay DECIMAL(20,4) NOT NULL, AddressId INT REFERENCES [Address](AddressId));I have above tableI want to modify the above script to creat a check constraint on yearlyPay such that Yearlypay< Payment.MaxPay and Yearlypay >Payment.MaxPaywhere Payment is another table.Also I don't want to create the constraint separately.. but want to create it while creating the table..Please suggest |
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2014-04-02 : 07:06:49
|
quote: Originally posted by Kimi86I want to modify the above script to creat a check constraint on yearlyPay such that Yearlypay< Payment.MaxPay and Yearlypay >Payment.MaxPay
Is this a typo? It's not possible for a value to be both less than and greater than another value.quote: where Payment is another table.
The only inter-table constraints SQL Server supports are foreign keys, and they are based only on equality of values. A check constraint cannot reference another table, unless you use a user-defined function to perform the comparison. While this is possible it will likely cause poor performance. |
|
|
|
|
|