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

From SQLZOO
Jump to: navigation, search
(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</...")
 
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
+
This is in the SQL standard ALTER TABLE: http://sqlzoo.net/sql92.html#alter_table_statement
<a href="http://sqlzoo.net/sql92.html#alter_table_statement">ALTER TABLE</a>
+
 
</div>
 
</div>
 
<source lang=sql class='tidy'>DROP TABLE a</source>
 
<source lang=sql class='tidy'>DROP TABLE a</source>

Revision as of 16:52, 12 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: http://sqlzoo.net/sql92.html#alter_table_statement

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