SQL Constraints: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 4: Line 4:


=<tt>NOT NULL</tt> Constraint=
=<tt>NOT NULL</tt> Constraint=
<syntaxhighlight lang='sql'>
CREATE TABLE ...
( ...
  somecolumn varchar(30) NOT NULL,
  ...
);
</syntaxhighlight>
Also see: {{Internal|SQL#SQL_NULL|<tt>NULL</tt>}}
Also see: {{Internal|SQL#SQL_NULL|<tt>NULL</tt>}}



Revision as of 00:02, 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)
);

Check Constraint

CREATE TABLE ...
( ...
  eye_color CHAR(2) CHECK (eye_color IN ('BR', 'BL', 'GR')),
  ...
);