SQL Constraints: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 21: Line 21:
);
);
</syntaxhighlight>
</syntaxhighlight>
=Foreign Key Constraint=
<syntaxhighlight lang='sql'>
CREATE TABLE ...
( ...
  CONSTRAINT fk_someconstraint FOREIGN KEY (somecolumn)
);
</syntaxhighlight>
=Check Constraint=
=Check Constraint=
<syntaxhighlight lang='sql'>
<syntaxhighlight lang='sql'>

Revision as of 00:03, 23 May 2024

Internal

Overview

NOT NULL Constraint

CREATE TABLE ...
( ...
  somecolumn varchar(30) NOT NULL, 
  ...
);

Also see:

NULL

Primary Key Constraint

CREATE TABLE ...
( ...
  CONSTRAINT pk_someconstraint PRIMARY KEY (somecolumn)
);

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')),
  ...
);