更改主键

编程入门 行业动态 更新时间:2024-10-25 18:33:12
本文介绍了更改主键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在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.

更多推荐

更改主键

本文发布于:2023-10-20 03:27:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1509708.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:主键

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!