微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

postgresql 修改表结构,添加索引

postgresql 修改表结构,添加索引

//添加一个表字段 testuser=> alter table test add sex integer; ALTER TABLE testuser=> \d test Table "public.test" Column | Type | Modifiers --------------+-----------------------+--------------------------------------------------- id | integer | not null default nextval('seq_test_id'::regclass) name | character varying(32) | date_created | date | sex | integer | Indexes: "testuser_id_pk" PRIMARY KEY,btree (id) //修改表字段类型 testuser=> alter table test alter sex type varchar(1); ALTER TABLE testuser=> \d test Table "public.test" Column | Type | Modifiers --------------+-----------------------+--------------------------------------------------- id | integer | not null default nextval('seq_test_id'::regclass) name | character varying(32) | date_created | date | sex | character varying(1) | Indexes: "testuser_id_pk" PRIMARY KEY,btree (id) //创建唯一索引 testuser=> create unique index unique_name on test(name); CREATE INDEX testuser=> \d test Table "public.test" Column | Type | Modifiers --------------+-----------------------+--------------------------------------------------- id | integer | not null default nextval('seq_test_id'::regclass) name | character varying(32) | date_created | date | sex | character varying(1) | Indexes: "testuser_id_pk" PRIMARY KEY,btree (id) "unique_name" UNIQUE,btree (name) //表字段改名 testuser=> alter table test rename sex to age; ALTER TABLE testuser=> \d test Table "public.test" Column | Type | Modifiers --------------+-----------------------+--------------------------------------------------- id | integer | not null default nextval('seq_test_id'::regclass) name | character varying(32) | date_created | date | age | character varying(1) | Indexes: "testuser_id_pk" PRIMARY KEY,btree (name) //删除表字段 testuser=> alter table test drop age; ALTER TABLE

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐