SQL Constraints: Difference between revisions
Jump to navigation
Jump to search
Line 22: | Line 22: | ||
); | ); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
The primary key constraint can also be added after table creation with <code>ALTER TABLE</code>. | |||
=Foreign Key Constraint= | =Foreign Key Constraint= |
Revision as of 00:06, 23 May 2024
Internal
Overview
NOT NULL Constraint
CREATE TABLE ...
( ...
somecolumn varchar(30) NOT NULL,
...
);
Also see:
Primary Key Constraint
CREATE TABLE ...
( ...
CONSTRAINT pk_someconstraint PRIMARY KEY (somecolumn)
);
The primary key constraint can also be added after table creation with ALTER TABLE
.
Foreign Key Constraint
CREATE TABLE ...
( ...
CONSTRAINT fk_someconstraint FOREIGN KEY (somecolumn)
);
Check Constraint
CREATE TABLE ...
( ...
eye_color CHAR(2) CHECK (eye_color IN ('BR', 'BL', 'GR')),
...
);