如何ALTER一个PostgreSQL表,并使一个列是唯一的? [英] How do I ALTER a PostgreSQL table and make a column unique?

查看:151
本文介绍了如何ALTER一个PostgreSQL表,并使一个列是唯一的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在PostgreSQL中有一个表格,其中模式如下所示:

  CREATE TABLEfoo_table(
idserial NOT NULL PRIMARY KEY,
permalinkvarchar(200)NOT NULL,
textvarchar(512)NOT NULL,
timestamp



现在我想通过ALTER表。

解决方案




p>我想出了从PostgreSQL文档,确切的语法是:

  ALTER TABLE the_table ADD CONSTRAINT constraint_name UNIQUE ; 

感谢 Fred


I have a table in PostgreSQL where the schema looks like this:

CREATE TABLE "foo_table" (
    "id" serial NOT NULL PRIMARY KEY,
    "permalink" varchar(200) NOT NULL,
    "text" varchar(512) NOT NULL,
    "timestamp" timestamp with time zone NOT NULL
)

Now I want to make the permalink unique across the table by ALTER-ing the table. Can anybody help me with this?

TIA

解决方案

I figured it out from the PostgreSQL docs, the exact syntax is:

ALTER TABLE the_table ADD CONSTRAINT constraint_name UNIQUE (thecolumn);

Thanks Fred.

这篇关于如何ALTER一个PostgreSQL表,并使一个列是唯一的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆