1、更改表名
alter table 表名 rename to 新表名
2、更改字段名
alter table 表名 rename 字段名 to 新字段名
3、更改字段类型
如:ID 字段 原类型为 character varying(50) 新类型为integer
其中,ID中原有数据为1,2,3等数字用如下语句更改
alter table dbo.titemtype alter column id type integer using to_number(id,'9');
3.2、更改字段类型
alter table m_serv_score_reply111 alter column correct_flag type CHARACTER VARYING(10)
alter table l_cert_apply alter column cert_type type BIGINT USING cert_type::bigint
4、更改长度
alter table sp_landing_page111 alter column page_title type CHARACTER VARYING(500)
5、查询sql执行效率
explain
6、增加新字段
ALTER TABLE sp_sale_article111 ADD editorial_board_id BIGINT?
7、删除索引
alter table table_name drop index index_name
8、添加索引 联合主键(a_sale为表名)
CREATE UNIQUE INDEX un_a_sale ON a_sale (sale_type,reference_id);
9、语句分析 用时 耗资源数
EXPLAIN ANALYZE
10、随机排序
select * from l_score order by random();
postgresql 基础sql
于 2021-11-24 17:56:39 首次发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)