As often with a SQL related question, it depends on the DBMS. Some DBMSs allow combining ALTER table operations, separated by commas. For example...
Informix :
ALTER TABLE one ADD two_id INTEGER, ADD CONSTRAINT FOREIGN KEY(two_id) REFERENCES two(id);
The syntax of IBM DB2 LUW is similar, repeating the ADD keyword, but (if I read the diagram correctly), without requiring a comma to separate the added elements.
Microsoft SQL Server Syntax :
ALTER TABLE one ADD two_id INTEGER, FOREIGN KEY(two_id) REFERENCES two(id);
Some others do not allow you to combine ALTER TABLE operations. Standard SQL allows only one operation in an ALTER TABLE statement, so in standard SQL this must be done in two steps.
Jonathan Leffler Jul 15 '13 at 1:59 2013-07-15 01:59
source share