更改主键 [英] Change Primary Key

查看:75
本文介绍了更改主键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Oracle中有一个表,该表具有以下架构:

I have a table in Oracle which has following Schema:

City_ID  Name  State  Country  BuildTime  Time

当我声明表时,我的主键既是City_ID又是BuildTime,但是现在我想将主键更改为三列:

When i declared the table my primary key was both City_ID and the BuildTime but now I want to change the primary key to three columns:

City_ID  BuildTime  Time

如何更改主键?

推荐答案

假设您的表名是city,而现有的主键是pk_city,则您应该能够执行以下操作:

Assuming that your table name is city and your existing Primary Key is pk_city, you should be able to do the following:

ALTER TABLE city
DROP CONSTRAINT pk_city;

ALTER TABLE city
ADD CONSTRAINT pk_city PRIMARY KEY (city_id, buildtime, time);

确保没有timeNULL的记录,否则您将无法重新创建约束.

Make sure that there are no records where time is NULL, otherwise you won't be able to re-create the constraint.

这篇关于更改主键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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