oracle中设置主键
Posted s硕s
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了oracle中设置主键相关的知识,希望对你有一定的参考价值。
1.创建表
create table "c_user"( "id" number primary key, "username" varchar(255), "password" varchar(255), "p_name" varchar(255), "p_number" varchar(255), "p_date" varchar(255), "p_referenceNumber" varchar(255), "tech_area" varchar(255), "platformLevel" varchar(255), "address" varchar(255), "permission" int(10), "type1" varchar(255), "union1" int(10), "BTHconStruction" int(10), "service1" varchar(255), "service2" varchar(255), "service3" varchar(255), "course1" varchar(255), "course2" varchar(255), "course3" varchar(255), "relyName" varchar(255), "credit" varchar(255), "relylegalName" varchar(255), "phone" varchar(255), "unitType" varchar(255), "constructionUnit" varchar(255), "directorName" varchar(255), "directorSex" varchar(255), "directorBirthyear" varchar(255), "directorTitle" varchar(255), "directorProfessional" varchar(255), "directorEducation" varchar(255), "directorDegree" varchar(255), "directorTele" varchar(255), "directorPhone" varchar(255), "directorEmail" varchar(255), "webName" varchar(255), "webSite" varchar(255), "addrplatformAddressess" varchar(255), "email" varchar(255), "state" int(2), "u_type" int(6), "p_type" int(2) );
#查看约束
select * from user_constraints;
////设置主键自增////
2.创建序列
select * from user_constraints;
#查看序列
select * from user_sequences;
3.设置触发器 //若表名为小写时,操作时应加“”号查找,列字段相同,在NAvicat中需要,eclipse可以不用。
create or replace trigger c_user_trigger before insert on "c_user" for each row when(new."id" is null) begin select c_user_id_seq.nextval into:new."id" from dual; end;
#查看触发器
select * from user_triggers;
#测试
commit;//命令行操作需要 select * from "c_user";
以上是关于oracle中设置主键的主要内容,如果未能解决你的问题,请参考以下文章