oracle删除主键约束的问题m
2013-11-09 18:30
459 查看
oracle“删除”主键约束的方法有两个<write by SnowShana / qq:449394683>
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);再次添加成功
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删除主键约束的同时删除索引
- oracle 数据按主键删除慢问题的解决方法
- Oracle主键外键 约束的 创建,添加和删除
- Oracle中出现“名称已被一现有约束条件占用”问题 怎么查找约束?怎么删除约束???
- hibernate中删除表遇到主键被外键引用违反完整约束条件不能删除的问题
- 每日雕蟲一技[2013-04-10]Oracle一次性删除主键约束和这个索引特殊语法
- oracle 数据按主键删除慢问题处理过程
- Oracle主键外键 约束的 创建,添加和删除
- oracle删除主键查看主键约束及创建联合主键
- 关于oracle表已设置主键自增仍报违反唯一约束问题
- oracle的主键约束的添加和删除
- Oracle删除约束和主键的语句
- Oracle中出现“名称已被一现有约束条件占用”问题 怎么查找约束?怎么删除约束???
- JAVA hibernate中删除表遇到主键被外键引用,违反完整约束条件,不能删除的问题
- oracle删除主键查看主键约束及创建联合主键
- 如何删除通过主键和唯一约束创建的索引
- oracle约束+check+暴力删除表,无视外键+查看用户创建的表+查看约束
- 主键约束自动建立索引问题
- 关于mysql删除唯一约束的问题(求解答)