Difference between revisions of "ALTER TABLE ... ADD constraint"

From SQLZOO
Jump to: navigation, search
Line 5: Line 5:
 
We can add a constraint
 
We can add a constraint
 
<ul><li>a foreign key reference</li><li>a UNIQUE requirement</li><li>a CHECK constraint</li></ul>
 
<ul><li>a foreign key reference</li><li>a UNIQUE requirement</li><li>a CHECK constraint</li></ul>
This is in the SQL standard ALTER TABLE: http://sqlzoo.net/sql92.html#alter_table_statement
+
This is in the SQL standard [http://sqlzoo.net/sql92.html#alter_table_statement ALTER TABLE]
 
</div>
 
</div>
 
<source lang=sql class='tidy'>DROP TABLE a</source>
 
<source lang=sql class='tidy'>DROP TABLE a</source>

Revision as of 09:19, 18 July 2012

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 ALTER TABLE

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

Variants
Actions
Reference
Toolbox
Google AdSense