postgres基本应用

postgres 数据库

为已有的字段添加默认值

ALTER TABLE table_name ALTER COLUMN column_name SET DEFAULT default_value;

删除默认值

ALTER TABLE table_name ALTER COLUMN column_name DROP DEFAULT;

给postgre添加自增字段

方法一:
CREATE TABLE customers  
(  
  customerid SERIAL primary key ,  
  companyname character varying,  
  contactname character varying,  
  phone character varying,  
  country character varying  
)

方法二:

CREATE SEQUENCE event_id_seq  
START WITH 1  
INCREMENT BY 1  
NO MINVALUE  
NO MAXVALUE  
CACHE 1;  

alter table event alter column id set default nextval('event_id_seq');
重置序列
 ALTER SEQUENCE tab_seq RESTART WITH 1;
添加索引
单字段索引:
CREATE INDEX index_name ON table_name (field1);
联合索引:
CREATE INDEX index_name ON table_name (field1,field2);
数据之间导入导出
insert into chronic(name, attr, content )
select name, attr, content from disease where name = '高血脂'
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×