Examples Using ALTER TABLE
-
Adding the
CAPITAL
column to theCOUNTRY
table.ALTER TABLE COUNTRY ADD CAPITAL VARCHAR(25);
-
Adding the
CAPITAL
column with theNOT NULL
andUNIQUE
constraint and deleting theCURRENCY
column.ALTER TABLE COUNTRY ADD CAPITAL VARCHAR(25) NOT NULL UNIQUE, DROP CURRENCY;
-
Adding the
CHK_SALARY
check constraint and a foreign key to theJOB
table.ALTER TABLE JOB ADD CONSTRAINT CHK_SALARY CHECK (MIN_SALARY < MAX_SALARY), ADD FOREIGN KEY (JOB_COUNTRY) REFERENCES COUNTRY (COUNTRY);
-
Setting default value for the
MODEL
field, changing the type of theITEMID
column and renaming the MODELNAME column.ALTER TABLE STOCK ALTER COLUMN MODEL SET DEFAULT 1, ALTER COLUMN ITEMID TYPE BIGINT, ALTER COLUMN MODELNAME TO NAME;
-
Restarting the sequence of an identity column.
ALTER TABLE objects ALTER ID RESTART WITH 100;
-
Changing the computed columns
NEW_SALARY
andSALARY_CHANGE
.ALTER TABLE SALARY_HISTORY ALTER NEW_SALARY GENERATED ALWAYS AS (OLD_SALARY + OLD_SALARY * PERCENT_CHANGE / 100), ALTER SALARY_CHANGE COMPUTED BY (OLD_SALARY * PERCENT_CHANGE / 100);