加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-13 17:11:22 所属栏目:百科 来源:网络整理
导读:1.数据库的连接 使用以下配置 jdbc3.postgre.driverClassName=org.postgresql.Driverjdbc3.postgre.url=jdbc:postgresql://localhost:5432/postgres #最后为数据库名jdbc3.postgre.username=xxxxjdbc3.postgre.password=xxxxxx 2.创建主键自增的表(使用图形

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语句转移到其他数据库的时候主键的设置会报错,移除设置主键的语句之后就好了

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读