Skip to content

CONSTRAINT

CREATE TABLE Orders (
OrderID int NOT NULL,
OrderNumber int NOT NULL,
PersonID int,
PRIMARY KEY (OrderID),
CONSTRAINT UC_Order UNIQUE (OrderNumber, PersonID)
);
Query OK, 0 rows affected (0.02 sec)

The SQL code creates a new table named ‘Orders’, with three columns: OrderID, OrderNumber, and PersonID. The Constraint ‘UC_Order’ is specified to ensure that the combination of OrderNumber and PersonID values in this table is unique. If any insertion attempts to breach this constraint (add duplicate combination), MySQL will prevent it. The PRIMARY KEY constraint ensures that OrderID is always unique.