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</...")
 
 
(2 intermediate revisions by one user not shown)
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 [http://sqlzoo.net/sql92.html#alter_table_statement ALTER TABLE]
<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>
Line 19: 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 09: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