如何在Oracle 11g中的表上添加约束

时间:2018-03-15 11:56:27

标签: oracle11g

所以我有一个帐户表,员工表和一个客户表。如何在帐户表上设置约束,以便员工不能成为他/她工作的同一分支的客户。

帐户代码表

create type account_type as object(
accNum number,
accType varchar2(15),
balance number, 
bID ref branch_type,
inRate number,
limitOfFreeOD number,
custID ref customer_type,
openDate DATE)
/
create table account_table of account_type(
primary key (accNum))
/

员工表代码

create type employee_type as object(
empID integer,
eName EmployeeName,
eAddress EmployeeAddress,
eContact EmployeeContact,
phone tp_phone_array,
supervisorID ref employee_type,
eDetails EmployeeWorkDetails,
bID ref branch_type,
joinDate Date);
/
create table employee_table of employee_type(
primary key (empID))
/

客户表代码

create type customer_type as object(
custID number,
cName customerName,
cAddress customerAddress,
cHomeContact custhomeContact,
cMobile tp_mobile_array,
cTaxDetails custTaxDetails)
/

create table customer of customer_type(
primary key (custID))
/

目前我在帐户表中添加了这样的普通客户数据:

insert into account_table
select account_type('1520','current','4154.20',ref(b),'0.090','200',ref(c),'20-Aug-16')
from branch b
where b.bID = '500'
and c.custID = '301';
/

这些是表格属性:

帐户(accNum,accType,balance,bID,inRate,limitOfFreeOD,openDate)

员工(empID,street,city,postCode,title,firstName,surName,empHomePhone, empMobile1,empMobile2,supervisorID,position,salary,niNum,bID,joinDate)

客户(custID,street,city,postCode,title,firstName,surName,custHomePhone, custMobile1,custMobile2,niNum)

有任何帮助吗?感谢。

0 个答案:

没有答案