如何使用ALTER TABLE添加新列并使其唯一? [英] How to use ALTER TABLE to add a new column and make it unique?

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

问题描述

如何使用 ALTER TABLE 添加新列并使其唯一?

How do I use ALTER TABLE to add a new column and make it unique?

推荐答案

取决于DBMS,但我认为以下内容非常易于移植:

Depends on the DBMS, but I think the following is quite portable:

ALTER TABLE table_name ADD column_name datatype
ALTER TABLE table_name ADD UNIQUE (column_name)

如果要给 UNIQUE 约束,您可以使用以下命令替换最后一个命令:

If you want to give a name to the UNIQUE constraint, you could replace the last command with this:

ALTER TABLE table_name ADD CONSTRAINT constraint_name UNIQUE (column_name)

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

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