当前位置:首页 > 千层云服务器 > 正文

怎么在postgresl中添加约束

在postgresl中添加约束的方法:1.启动postgresql服务;2.登录postgresql数据库;3.使用数据库;4.执行命令添加约束;

怎么在postgresl中添加约束

具体步骤如下:

1.首先,在命令行中启动postgresql服务;

net start postgresql

2.postgresql服务启动后,在命令行中登录到postgresql数据库;

psql -h -U

3.登录到postgresql数据库后,在postgresql选择一个数据库并使用;

\c text

4.进入到数据库后,在数据库中执行以下命令即可添加约束;

1)添加列约束

CREATE TABLE prefer (

product_no integer UNIQUE,

name text,

price numeric

);

2)添加表约束

CREATE TABLE prefer (

product_no integer,

name text,

price numeric,

UNIQUE (product_no)

);

如果您对该产品感兴趣,请填写办理(客服微信:xiaoxiongyidong)

为您推荐:

发表评论

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

在线客服