diff --git a/Document/PG增加列.txt b/Document/PG增加列.txt index 473d0603..6bc5f357 100644 --- a/Document/PG增加列.txt +++ b/Document/PG增加列.txt @@ -10,4 +10,8 @@ where relkind = 'r' and relname like 'j%_r' and relname not like 'pg_%' and rel -- 设置默认值 select 'DO $$ BEGIN BEGIN ALTER TABLE '||relname||' ALTER COLUMN recordyear SET DEFAULT 2020; EXCEPTION WHEN duplicate_column THEN RAISE NOTICE ''column recordyear already exists''; END; END;$$;' as tabname from pg_class c -where relkind = 'r' and relname like 'j%_r' and relname not like 'pg_%' and relname not like 'sql_%' order by relname; \ No newline at end of file +where relkind = 'r' and relname like 'j%_r' and relname not like 'pg_%' and relname not like 'sql_%' order by relname; + + +-- 删除默认值 +ALTER TABLE table_name ALTER COLUMN column_name DROP DEFAULT; \ No newline at end of file