約束
create table goods(goodsid char(8) primary key, --主鍵
goodsname varchar2(20),
unitprice number(10,2) check (unitprice >0), --檢查
category varchar2(10),
vendor varchar2(20));
create table customer( customerid char(8) primary key,
name varchar2(30) not null,
address varchar2(30),
email varchar2(30) unique,
*** char(2) default '男' check (*** in ('男', '女')),
cardid char(10));
create table purchase( customerid char(8) references customer(customerid), --列級定義不用foreign key
goodsid char(8) references goods(goodsid),
nums number(10) check ( nums between 1 and 30));
alter table goods modify goodsname not null;
alter table customer add constraint cardunique unique(cardid);
alter table customer add constraint addresscheck check(address in('和平', '西青', '南開');
alter table customer drop constraint cardunique;
alter table customer drop primary key [cascade]; --若存在主外來鍵關係,需要cascade
select constraint_name, constraint_type, status, validated from user_constraints where table_name='customer';
--檢視約束資訊
select column_name, position from user_cons_columns where constraint_name='addresscheck'; --檢視約束列名
列級定義--在定義列的同時定義約束
create table department(deptid number(2) constraint pk_department primary key,
name varchar2(12)
loc varchar2(12));
表級定義--在定義了所有列後,再定義約束,注意not null約束只能在列級上定義
create table employ(employid number(4),
name varchar2(20),
deptid number(2),
constraint pk_emplyee primary key (employid),
constraint fk_dept foreign key (deptid) references departmt(deptid));
oracle學習記錄之十五
pl sql 儲存過程 create table mytest name varchar2 20 passwd varchar2 20 sql create or replace procedure spro1 is 2 begin 3 insert into mytest values xiaom...
oracle學習記錄之十七
使用isql plus 檢視埠配置 d oracle product 10.1.0 db 1 install 下的portlist.ini ultra search http 埠號 5620 enterprise manager agent port isql plus http 埠號 5560 檢...
Oracle學習記錄
管理員賬戶使用方案.物件 select from scott.emp 給scott使用者賦連線許可權 grant create session to scott 撤銷scott使用者的連線許可權 revoke create session from scott 建立使用者zx,密碼為123456 c...