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

From SQLZOO
Jump to: navigation, search
 
Line 18: Line 18:
 
<div class="ecomm e-access" style="display: none">The check is not supported.</div>
 
<div class="ecomm e-access" style="display: none">The check is not supported.</div>
 
<div class="ecomm e-oracle" style="display: none">
 
<div class="ecomm e-oracle" style="display: none">
<a href="http://sqlzoo.napier.ac.uk/big/B/s/a/statements_32a.htm#2103928">ALTER TABLE t DROP COLUMN c</a>
+
[http://sqlzoo.napier.ac.uk/big/B/s/a/statements_32a.htm#2103928 ALTER TABLE t DROP COLUMN c]
 
</div>
 
</div>
 
<div class="ecomm e-db2" style="display: none">
 
<div class="ecomm e-db2" style="display: none">
<a href="https://aurora.vcu.edu/db2help/db2s0/frame3.htm#sqls0604">
+
[https://aurora.vcu.edu/db2help/db2s0/frame3.htm#sqls0604 ALTER TABLE documentation.]<br/>
ALTER TABLE documentation.</a><br/>
+
 
DB2 seemingly does not permit this operation - any help would be appreciated.
 
DB2 seemingly does not permit this operation - any help would be appreciated.
 
</div>
 
</div>
<div class="ecomm e-postgres" style="display: none"><a href="http://www.ca.postgresql.org/users-lounge/docs/7.0/user/sql-altertable.htm">ALTER TABLE</a></div>
+
<div class="ecomm e-postgres" style="display: none">[http://www.ca.postgresql.org/users-lounge/docs/7.0/user/sql-altertable.htm ALTER TABLE]</div>
 
</div>
 
</div>
 
{{CREATE and DROP ref}}
 
{{CREATE and DROP ref}}

Latest revision as of 10:42, 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