Mar*_*arc 7 sql postgresql auto-increment
我有一个db中的现有表,其他几个FK,SQL如下:
CREATE TABLE forecastsource (
source_id integer DEFAULT nextval(('public.forecastsource_source_id_seq'::text)::regclass) NOT NULL,
source_name character varying NOT NULL
);
Run Code Online (Sandbox Code Playgroud)
我想从id字段中删除自动增量,然后将其移动到一个int字段(不丢失表中的当前数据).除了删除和重新创建表之外,我该怎么做?
a_h*_*ame 17
只需删除默认值:
ALTER TABLE forecastsource ALTER COLUMN source_id DROP DEFAULT;
Run Code Online (Sandbox Code Playgroud)
您可能还想删除序列.
| 归档时间: |
|
| 查看次数: |
4579 次 |
| 最近记录: |