如何在Oracle 10g中分配外键?
我正在尝试在Oracle 10g中分配外键。但是错误显示为 ORA-907:缺少右括号 我有三张桌子 TBL客户如何在Oracle 10g中分配外键?,oracle,Oracle,我正在尝试在Oracle 10g中分配外键。但是错误显示为 ORA-907:缺少右括号 我有三张桌子 TBL客户 TBL产品 特级销售 create table tblSales (SalesID int primary key, ProductId int foreign key references tblProducts(ProductId), CustomerID int foreign key references tblCustomer(CustomerID), SalesPrice
TBL产品
特级销售
create table tblSales
(SalesID int primary key,
ProductId int foreign key references tblProducts(ProductId),
CustomerID int foreign key references tblCustomer(CustomerID),
SalesPrice numeric,
SalesDate date);
你能告诉我出了什么问题。你的语法必须看起来像:
create table tblSales (SalesID int,
ProductId int ,
CustomerID int ,
SalesPrice numeric,
SalesDate date,
CONSTRAINT sales_pk PRIMARY KEY (SalesID ),
CONSTRAINT fk_produkt
foreign key (ProductId)references tblProducts(ProductId),
CONSTRAINT fk_customer
foreign key (CustomerID)references tblCustomer(CustomerID)
);
您的语法必须如下所示:
create table tblSales (SalesID int,
ProductId int ,
CustomerID int ,
SalesPrice numeric,
SalesDate date,
CONSTRAINT sales_pk PRIMARY KEY (SalesID ),
CONSTRAINT fk_produkt
foreign key (ProductId)references tblProducts(ProductId),
CONSTRAINT fk_customer
foreign key (CustomerID)references tblCustomer(CustomerID)
);
对于内联外键,您不指定
外键
关键字:
create table tblSales
(
SalesID int primary key,
ProductId int references tblProducts(ProductId),
CustomerID int references tblCustomer(CustomerID),
SalesPrice numeric,
SalesDate date
);
对于内联外键,您甚至不需要指定目标列:
create table tblSales
(
SalesID int primary key,
ProductId int references tblProducts,
CustomerID int references tblCustomer,
SalesPrice numeric,
SalesDate date
);
SQLFiddle示例:
作为旁注:在每个表前面加上
tbl
并没有真正意义。如果您正在编程,您是否在每个类前面加上Cls
,或者如果您正在命名一个人,您是否在每个名字前面加上Pers
对于内联外键,您不指定外键
关键字:
create table tblSales
(
SalesID int primary key,
ProductId int references tblProducts(ProductId),
CustomerID int references tblCustomer(CustomerID),
SalesPrice numeric,
SalesDate date
);
对于内联外键,您甚至不需要指定目标列:
create table tblSales
(
SalesID int primary key,
ProductId int references tblProducts,
CustomerID int references tblCustomer,
SalesPrice numeric,
SalesDate date
);
SQLFiddle示例:
作为旁注:在每个表前面加上
tbl
并没有真正意义。如果您正在编程,您是否在每个类前面加上Cls
,或者如果您正在命名一个人,您是否在每个名字前面加上Pers
直到同样的问题出现..亲爱的,你能提供另外两个table create语句吗?@Dhavalghevaria抱歉,我忘了一个逗号。已经添加了它。直到同样的问题出现..亲爱的,你能提供另外两个table create语句吗?@Dhavalghevaria抱歉,我忘了一个逗号。我已经添加了它。