Who Can Alter a Table?
The ALTER TABLE
statement can be executed by:
-
The owner of the table
-
Users with the
ALTER ANY TABLE
privilege
The ALTER TABLE
statement can be executed by:
The owner of the table
Users with the ALTER ANY TABLE
privilege
ALTER TABLE
Adding the CAPITAL
column to the COUNTRY
table.
ALTER TABLE COUNTRY
ADD CAPITAL VARCHAR(25);
Adding the CAPITAL
column with the NOT NULL
and UNIQUE
constraint and deleting the CURRENCY
column.
ALTER TABLE COUNTRY
ADD CAPITAL VARCHAR(25) NOT NULL UNIQUE,
DROP CURRENCY;
Adding the CHK_SALARY
check constraint and a foreign key to the JOB
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 the ITEMID
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
and SALARY_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);