sql更换表结构

案列

-- 查看表结构
SELECT HG_DUMP_SCRIPT('public.test');

-- 创建新的结构表
CREATE TABLE public.test (
    name text NOT NULL,
    commits text
    ,PRIMARY KEY (name)
);

-- 创建新的结构表
CREATE TABLE public.test_1 (
    name text NOT NULL,
    commits text,
    age text
    ,PRIMARY KEY (name, age)
);

-- 把原来test的数据插入到test_1中
INSERT INTO test_1 SELECT 
name,
commits,
'设置默认'
from test

-- 查看表数据
select COUNT(*) from test_1
select COUNT(*) from test

 -- 删除test表
DROP TABLE test

-- 把test_1重命名test
ALTER TABLE test_1 RENAME TO test;
posted @ 2023-01-04 17:18  lxd670  阅读(47)  评论(0编辑  收藏  举报