postgresql
postgres
sql
5 years, 2 months ago
-- New versions of postgres
-- adding as primary key
ALTER TABLE my_schema.my_table ADD COLUMN id SERIAL PRIMARY KEY;
--without primary key aslo you can use
ALTER TABLE my_schema.my_table ADD COLUMN id SERIAL
-- For old versions
ALTER TABLE my_table ADD COLUMN id INTEGER;
CREATE SEQUENCE my_id_seq OWNED BY my_table.id;
ALTER TABLE my_table ALTER COLUMN id SET DEFAULT nextval('my_id_seq');
UPDATE my_table SET id = nextval('my_id_seq');
0 Comments
Please Login to Comment Here