SELECT ...
FROM ...
WHERE EXISTS (SELECT ... FROM ... WHERE ...)
CREATE TABLE CUSTOMERS(
ID INT NOT NULL,
NAME VARCHAR (20) NOT NULL,
AGE INT NOT NULL CHECK (AGE >= 18),
PRIMARY KEY (ID)
);
If CUSTOMERS table has already been created, then to add a CHECK constraint to AGE column, you would write a statement similar to the following:
ALTER TABLE CUSTOMERS
MODIFY AGE INT NOT NULL CHECK (AGE >= 18 );
Naming the constraint in multiple columns as well:
ALTER TABLE CUSTOMERS
ADD CONSTRAINT myCheckConstraint CHECK(AGE >= 18);
CREATE TABLE CUSTOMERS(
ID INT NOT NULL,
NAME VARCHAR (20) NOT NULL,
ADDRESS CHAR (25) ,
PRIMARY KEY (ID)
);
If CUSTOMERS table has already been created, then to add a NOT NULL constraint to SALARY column in Oracle and MySQL:
ALTER TABLE CUSTOMERS
MODIFY SALARY DECIMAL (18, 2) NOT NULL;
Read more: NOT NULL Constraint
Войдите чтобы поставить Нравится
Войдите чтобы прокомментировать