Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Modifying columns
Modifying identities
8. Canceling auto-generation of identities
Modifying sequences
Summary

Instruction

Great! Now, we'll show you how you can cancel the auto-generation of integer values from your table. Suppose we have the following table:

CREATE TABLE country (
  id integer GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
  name varchar(32),
  code char(2)
);

At some point, you want to stop the auto-generation of the identity in the column id. You can use the following code:

ALTER TABLE country ALTER COLUMN id DROP IDENTITY;

Once you run this code, the column id will not auto-generate numbers when you add further rows.

Exercise

Let's investigate another problem the agency has. We've created a table named costume in the following way:

CREATE TABLE costume (
  id integer GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
  name varchar(64),
  manufacturer varchar(32)
);

The agency wants to generate their own IDs now. Your task is to turn off auto-generation of the identity in the column id.