Oracle数据库修改主键

一、数据表有主键但无主键约束名

               先删除之前的主键,后添加主键

                           a.  alter table 表名 drop primary key;

                           b. alter table 表名 add primary key(想要更改的字段名称);

二、数据表有主键也有主键约束名

            (1)删除已有的主键约束名

                         a. 若已知主键约束名:alter table 表名 drop constraint 约束名 ;

                         b. 若不知主键约束名:

                                         select * from user_cons_columns c where c.table_name='表名';

                             先查询出改表的主键约束名,在执行

                                        alter table  表名 drop constraint 约束名;

           (2)增加新的主键约束

                         alter table 表名 add constraint 约束名 primary key(字段名);

猜你喜欢

转载自www.cnblogs.com/cn-star/p/12052976.html
今日推荐