您的位置:首页 > 数据库 > Oracle

Oracle 序列的创建与运用 内含约束补充内容

2016-07-30 14:11 323 查看
--添加主键约束
 	alter table 表名  add constraint 主键约束名 primary key (列名,..)
 
--添加外键约束
 	alter table 表名  add constraint 外键约束名 foreign key (列名) references 主表(列名)
--唯一约束
alter table 表名 add constraint  约束名  unique (列名)

--检查约束
alter table 表名 add constraint 约束名  check (列名条件)

--非空约束
alter table 表名 modify 字段名 字段类型  not null;

--删除约束
alter table 表名  drop constraint  约束名;
--创建序列
create sequence cid_seq  --序列名
start with 1000  --起始值
increment by 1 --每次增1
nomaxvalue  --无最大值
nocycle --不循环   --[cycle]循环
cache 10; --缓存
 --查询序列
 	select cid_seq.nextval from dual;--查询序列的下一个值
 	select cid_seq.currval from dual;--查询序列的当前值
--删除序列
	drop sequence cid_seq;
--修改表数据
 	update <表名>  set  <列名=值> where <条件>
--删除表数据
 	delete from  <表名> where <条件>
--创建classes表  ,然后用序列插入各组数据
create table classes(
      		cid int primary key,
        	cname varchar2(20) not null unique,
       		intro varchar2(1000)
 
 	)
 	insert into classes (cid,cname,intro)values (cid_seq.nextval,'软件1402','软件专业');
 	insert into classes (cid,cname,intro)values (cid_seq.nextval,'网络1401','网络专业');
 	insert into classes (cid,cname,intro)values (cid_seq.nextval,'信息1401','信息专业');

 	select * from classes;






[b]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  约束 Oracle 序列