创建外键的方法

方法一:
create table OrderMaster
(
  OrderID number primary key,
  UserName varchar2(20),
  OrderDate date
)

create table OrderDetail
(
  OrderID number,
  PName varchar2(20),
  Count number,
  constraint FK_OrderID foreign key(OrderID) references OrderMaster(OrderID)
)


方法二:

create table OrderDetail
(
  OrderID number,
  PName varchar2(20),
  Count number
)

alter table OrderDetail
add constraint FK_OrderID foreign key (OrderID) references OrderMaster(OrderID)

你可能感兴趣的:(sql)