本文介绍了更改主键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在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);确保没有time为NULL的记录,否则您将无法重新创建约束.
Make sure that there are no records where time is NULL, otherwise you won't be able to re-create the constraint.
更多推荐
更改主键
发布评论