oracle“删除”主键约束的方法有两个

1:alter table 表名 drop primary key;

这个是把主键从表中去除,而不是真正的删除主键

例子:

创建表:create table test_table_students (student_id number not null,student_name varchar(20) not null,student_telephone long not null);

创建主键:alter table test_table_students add constraint test_key_students primary key (student_id,student_name);

第一次插入数据:insert into test_table_students (student_id,student_name,student_telephone) values (1,'alice',136133);

第二次插入数据:insert into test_table_students (student_id,student_name,student_telephone) values (1,'peter',136133); 提示主键约束

第三次插入数据:insert into test_table_students (student_id,student_name,student_telephone) values (2,'alice',136133); 提示主键约束

删除主键约束:alter table test_table_students drop primary key;

第四次插入数据:insert into test_table_students (student_id,student_name,student_telephone) values (1,'peter',136134); 插入成功

第五次插入数据:insert into test_table_students (student_id,student_name,student_telephone) values (2,'alice',136135); 插入成功

删除刚才两行数据:delete from test_table_students where student_telephone=136134;delete from test_table_students where student_telephone=136135;

第二次添加主键约束:alter table test_table_students add constraint test_key_students primary key (student_id,student_name);约束名被占用

2:alter table 表名 drop constraint 约束名;

这个是把主键删除,可以再次添加同名主键

例子:

创建表:create table new_table_students (student_id number not null,student_name varchar(20) not null,student_telephone long not null);

创建主键:alter table new_table_students add constraint new_key_students primary key (student_id,student_name);

第一次插入数据:insert into new_table_students (student_id,student_name,student_telephone) values (1,'alice',136133);

第二次插入数据:insert into new_table_students (student_id,student_name,student_telephone) values (1,'peter',136133); 提示主键约束

第三次插入数据:insert into new_table_students (student_id,student_name,student_telephone) values (2,'alice',136133); 提示主键约束

删除主键约束:alter table new_table_students drop constraint new_key_students;

第四次插入数据:insert into new_table_students (student_id,student_name,student_telephone) values (1,'peter',136134); 插入成功

第五次插入数据:insert into new_table_students (student_id,student_name,student_telephone) values (2,'alice',136135); 插入成功

删除刚才两行数据:delete from new_table_students where student_telephone=136134;delete from new_table_students where student_telephone=136135;

第二次添加主键约束:alter table new_table_students add constraint new_key_students primary key (student_id,student_name);再次添加成功

如何删除oracle表的主键约束,oracle删除主键约束的问题m相关推荐

  1. oracle 删除空间不足,oracle表空间扩容、创建、删除(解决表空间不足问题)

    前言 整理一下之前使用oracle数据库遇到的表空间不足的问题,顺便水个博客. oracle表空间操作语句 1.改变已存在的数据文件的大小 ALTER TABLESPACE app_data ADD ...

  2. mysql中用于删除数据的是什么意思_在删除关系表中数据时,要先删除主表数据再删除从表数据。_学小易找答案...

    [单选题]在MySQL中,所有存储过程的信息存放在下列哪个数据库中 [填空题]拉伸试验能测定的塑性指标有: 和 . [单选题]下面查看视图的基本信息的语句中,正确的是 [单选题]下面关于视图建立的说法 ...

  3. oracle+表的更新日志,测试oracle插入 删除 更新表的日志开销

    ###############测试插入 删除 更新表的日志开销 创建表 SYS@orcl >create table ssr(id int); 查询表空间,sys默认system,插入数据后此分 ...

  4. oracle表分析都分析什么,oracle表分析

    analyze table tablename compute statistics; analyze index indexname compute statistics; 对于使用CBO很有好处, ...

  5. oracle表空间默认增长大小,Oracle 用户表空间查看、修改大小、设置自增长等

    分类: Oracle 首先登入某个用户,查看某个用户在哪个表空间下: select username,default_tablespace from user_users; 查看该用户下所有的表: s ...

  6. 查询oracle表空间是否满了,查看Oracle表空间大小的方法

    Oracle表空间大小的查看方法应该是我们都需要掌握的知识,下面就为您详细介绍查看Oracle表空间大小的方法,供您参考学习. 在数据库管理中,磁盘空间不足是DBA都会遇到的问题,问题比较常见. -- ...

  7. oracle表空间管理图形界面,Oracle表空间管理和优化

    Oracle 表空间管理和优化 1. TOM大神的表查询和授权语句create or replace procedure SHOW_SPACE(P_SEGNAME IN VARCHAR2, Oracl ...

  8. oracle范围分区表,Oracle表分区之范围分区-Oracle

    Oracle表分区之范围分区 以表中的一个列或一组列的值的范围分区 语法: [sql] PARTITION BY RANGE (column_name) (    www.2cto.com PARTI ...

  9. oracle表结构修改回滚,87.Oracle数据库SQL开发之 修改表内存——数据库事务的提交和回滚...

    87.Oracle数据库SQL开发之 修改表内存--数据库事务的提交和回滚 数据库事务(transaction)就是一组SQL语句,这组SQL语句时一个逻辑工作单元. 要永久性的记录事务中SQL语句的 ...

  10. 直接点oracle表编辑器,DbForge Studio for Oracle入门教程:如何在表编辑器中创建表...

    dbForge Studio for Oracle是一个功能强大的集成开发环境(IDE),它提供了通用的数据编辑工具来管理数据库内和外部数据,能够帮助Oracle开发者提高PL/SQL的编码速度. [ ...

最新文章

  1. 【每日一算法】使用二分法解决x 的平方根问题
  2. ajax长轮询 java web_Ajax长轮询
  3. linux内核中的每cpu变量
  4. hive hql文档_30分钟入门 Hive SQL(HQL 入门篇)
  5. Android自带Monkey测试
  6. 参考文献起止页码怎么写_论文参考文献怎么写?
  7. 级联MobileNet-V2实现CelebA人脸关键点检测(附训练源码)
  8. [转帖]linux /proc目录下的文件为何无法用vi编辑保存
  9. 稀疏矩阵-sparse 存储和转换
  10. 普鸥知识产权|如何申请美国外观专利?申请费用、时间、流程?
  11. 基因组测序 转录组测序
  12. onap桂林版部署教程
  13. php amr时长,amr是什么文件
  14. 物料-贴片电容-标签识别
  15. Android 播放视频
  16. 小程序源码:随机头像大全,多分类带历史记录-多玩法安装简单
  17. 腾讯99公益日-券券松鼠❤
  18. 用C语言求三位数的回文素数,C语言求回文素数
  19. [VB.NET源码]1-你好程序
  20. Go安装报错The installer has insufficient privileges to access thisdirectory: C:\ProgramData\.. 的解决方法

热门文章

  1. 实验六:派生类与继承
  2. 七、熵编码算法(1):基础知识
  3. uniapp 之 接入小程序客服
  4. 假期怎么玩,知道这几样轻松玩遍各地
  5. 一个好用的JSON转义工具网站,用于C开发
  6. 等保备案是等保测评吗?两者是什么关系?
  7. “万事回头看”:记得常回头看看
  8. 5个免费的高质量的自媒体学习网站,你值得拥有
  9. 甘肃增值税起征点变10万元 惠及61万小规模纳税人
  10. [Mysql] 插入数据