您的位置:首页 > 数据库

【postgresql】初次使用遇到的问题和总结

2015-12-16 11:26 281 查看

1.数据库的连接

使用以下配置

jdbc3.postgre.driverClassName=org.postgresql.Driver
jdbc3.postgre.url=jdbc:postgresql://localhost:5432/postgres   #最后为数据库名
jdbc3.postgre.username=xxxx
jdbc3.postgre.password=xxxxxx


2.创建主键自增的表(使用图形化界面navicat创建表的时候并没有找到主键自增的设置,所以只能使用sql语句),

A.使用serial关键字 ,这个方法是默认为id创建了一个序列,默认值为:nextval('test_1_id_seq'::regclass)

create table test _1(

id serial not null,

name varchar(255)

);


B.手动为table 创建序列

create sequence test_seq
start with 1
increment by 1
no maxvalue
no minvalue
cache 1;

alter table test_1 alter column id set default nextval('test_seq');


3.还有一点问题还没搞明白,我用图形化界面创建的表设置了主键,在导出sql语句转移到其他数据库的时候主键的设置会报错,移除设置主键的语句之后就好了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: