anthino12
anthino12

Reputation: 958

SQL - Check constraint with values from another table and in legit format

I have a table Orders(OrderID, OrderName, ClientCity, ClientNumber, ClientAddress, FullAddress). I have a task to make the FullAddress be in the following format: ClientCity/ClientAddress-ClientNumber).

I have a query but I don't know if it's correct: ALTER TABLE Orders ADD CONSTRAINT CHECK(FullAddress LIKE City'/'ClientAddress'-'ClientNumber)?

Upvotes: 0

Views: 27

Answers (1)

Conffusion
Conffusion

Reputation: 4475

Am I right, you want to check if the FullAddress value corresponds to the other client fields ?

This will not fill the FullAddress for you, only check if you have correctly filled it.

To check the FullAddress:

ALTER TABLE Orders 
    ADD CONSTRAINT CHECK(FullAddress = CONCAT(City,'/',ClientAddress,'-',ClientNumber))

Not clear why you use LIKE instead of =

Upvotes: 1

Related Questions