question

kenza avatar image
kenza asked

Modifying a constraint?

It seems like you can't modify a constraint, so I dropped it (successfully). But now I don't know how to recreate a similar, updated one... I did it manually, but is there some tcodes that I can write for it to do the same thing?

Context: There were 6 types of status reports. now there are 12 of them with their own description. I needed to make sure the db could take all 12 of them.

ALTER TABLE Sales.SalesOrderHeader
 DROP CONSTRAINT CK_SalesOrderHeader_Status; --OK

 ALTER TABLE Sales.SalesOrderHeader
 ADD CONSTRAINT CK_SalesOrderHeader_Status
	CHECK (Status >=0 AND Status <=12); --???? 


sqlsql-servermanagement studio
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

ThomasRushton avatar image ThomasRushton ♦♦ commented ·

This sounds like the sort of thing that would be better done by using a FOREIGN KEY CONSTRAINT - see https://docs.microsoft.com/en-us/sql/relational-databases/tables/primary-and-foreign-key-constraints?view=sql-server-2017#FKeys

0 Likes 0 ·

0 Answers

·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.