Wrox Home  
Search P2P Archive for: Go

  Return to Index  

sql_language thread: Constraints


Message #1 by "Mike" <mikeos1000@h...> on Wed, 25 Sep 2002 21:52:04
You can only add a column constraint when you add the column.

Add your constraint as a table constraint instead:

	ALTER TABLE Orders ADD CONSTRAINT con_Quantityinfive CHECK Quantity % 5=0;

--
Jeff Mason			Custom Apps, Inc.
Jeff@c...

-----Original Message-----
From: Mike [mailto:mikeos1000@h...]
Sent: Wednesday, September 25, 2002 9:52 PM
To: sql language
Subject: [sql_language] Constraints


Hi all,

I'm trying to add a constraint to an EXISTING column, to do so I have
written the code below but it doesn't work, note that I have also tried
it with the CHECK expression in parenthesis but it still doesn't work. I
imagine I'm way out here so any help would be appreciated. Note I'm using
SQL Server if that makes any difference. Here's the code:

ALTER TABLE Orders ALTER COLUMN Quantity INT
CONSTRAINT con_Quantityinfive CHECK Quantity % 5=0

I'm aware of the data integrity issues but the existing data in the
column conforms to this condition anyway.

Thanks


  Return to Index