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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 CHECK constraint

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-02-04 : 09:54:17
Molly writes "I have 2 columns: item_price and item_cost. I need to impose a constraint at the table level where item_price can never be more than three times the item_cost and also can never be below 120% of the item_cost."

Nazim
A custom title

1408 Posts

Posted - 2002-02-04 : 10:09:33

CREATE TABLE [dbo].[table1] (
[item_cost] [int] NULL ,
[item_price] [int] NULL
)
ALTER TABLE [dbo].[table1] WITH NOCHECK ADD
CONSTRAINT [CK_tta] CHECK (item_price < 3 * item_cost and item_price > 0.12 * item_cost)

HTH

--------------------------------------------------------------
Dont Tell God how big your Problem is , Tell the Problem how Big your God is
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-02-04 : 10:20:09
CREATE TABLE [dbo].[table1] (
[item_cost] [int] NULL ,
[item_price] [int] NULL
)
ALTER TABLE [dbo].[table1] WITH NOCHECK ADD
CONSTRAINT [CK_tta] CHECK (item_price < 3.00 * item_cost and item_price > 1.20 * item_cost)


The 0.12 you had originally would make it 12% instead of 120%. That would be REALLY BAD for the profit margin

Go to Top of Page

nrafiq
Starting Member

9 Posts

Posted - 2002-02-04 : 10:20:23
Hi Frined,

I think its a solution for query.

Create Table Sample(A Int, B int, constraint ABCheck Check (A <= (b * 3) And A <= b*120/100))



Rafi
Go to Top of Page

Nazim
A custom title

1408 Posts

Posted - 2002-02-04 : 10:22:12
yeah, am not too found of Molly's compay .

Just kidding

--------------------------------------------------------------
Dont Tell God how big your Problem is , Tell the Problem how Big your God is
Go to Top of Page

nrafiq
Starting Member

9 Posts

Posted - 2002-02-04 : 10:22:54
Sorry.

The above query should be like this.

Create Table AA(A Int, B int, constraint ABCheck Check (A <= (b * 3) And A >= b*120/100))


Rafi
Go to Top of Page
   

- Advertisement -