简体   繁体   English

如何在SQL中创建数据库,带有主键和自动增量的表

[英]How to create database,table with primary key and auto increment in SQL

我想创建一个表,它们有一个 ID int 主键,但是,我想手动插入值,这意味着我不需要 ID 自行增加?

In PostgreSQL these are totally different concepts.在 PostgreSQL 中,这些是完全不同的概念。

  1. you have primary keys你有主键
  2. You have sequence generators that can generate ints.您有可以生成整数的序列生成器。 A serial type is an int that gets its value from a sequence generator.串行类型是从序列生成器获取其值的 int。

The two have nothing to do with eachouther.两人没有任何关系。

Yes you can:是的你可以:

CREATE TABLE a (b int primary key);

You can also你也可以

CREATE TABLE a (b serial);

You can of course do both你当然可以两者都做

CREATE TABLE a (b serial primary key);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM