ALTER TABLE ... ADD constraint

From SQLZOO
Revision as of 15:47, 12 July 2012 by Marek (Talk | contribs) (Created page with "Add a constraint to a table. <div class='ht'> <div class=params>schema:scott</div> <div> We can add a constraint <ul><li>a foreign key reference</li><li>a UNIQUE requirement</...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Add a constraint to a table.

schema:scott

We can add a constraint

  • a foreign key reference
  • a UNIQUE requirement
  • a CHECK constraint

This is in the SQL standard <a href="http://sqlzoo.net/sql92.html#alter_table_statement">ALTER TABLE</a>

DROP TABLE a
CREATE TABLE a(x INTEGER, y INTEGER);
INSERT INTO a VALUES (1,2);
ALTER TABLE a ADD CHECK (y>0)