查询不能将外键用作另一个表oracle SQL的复合主键

时间:2016-01-01 02:32:44

标签: sql database oracle foreign-keys composite-primary-key

我正在尝试为SQL Oracle中的关联实体添加两个外键。我从另一个表中引用的主键是复合主键。当我尝试输入SQL时,它说

  

此列列表没有匹配的唯一键或主键

我用来创建tbl_customer

的代码
 CREATE TABLE tbl_Customer(
customer_id     NUMBER(4)
    CONSTRAINT pk_customer PRIMARY KEY,
CustomerName    VARCHAR2(50) NOT NULL,
Telephone       VARCHAR2(10),
CusEmail        VARCHAR2(20),
    CONSTRAINT cus_email UNIQUE(CusEmail),

location_id     NUMBER(4)
    CONSTRAINT fk_location_id references tbl_Location(location_id));

创建tbl_Vehicle的SQL

CREATE TABLE tbl_Vehicle(
   vehicle_id   NUMBER(4),
   PlateNo      VARCHAR2(10),
    CONSTRAINT pk_v PRIMARY KEY(vehicle_id,PlateNo),
   Brand        VARCHAR2(20),
   Model        VARCHAR2(10),
   TotalNoSeats     NUMBER(2),
   Class        VARCHAR2(4) NOT NULL,
        CONSTRAINT no_seats CHECK (TotalNoSeats<100),
     driver_id      NUMBER(4)
        CONSTRAINT fk_driveridV references tbl_Driver(driver_id),
     location_id    NUMBER(4)
        CONSTRAINT fk_locationV references tbl_Location(location_id));

关联表是

CREATE TABLE tbl_Customer_Vehicle(
customer_id NUMBER(4)
CONSTRAINT fk_customer_id references tbl_Customer(customer_id),
vehicle_id NUMBER(4)
CONSTRAINT fk_vehicle_id references tbl_Vehicle(vehicle_id)
);

错误在此行

 CONSTRAINT fk_vehicle_id references tbl_Vehicle(vehicle_id)
                                             *

这是错误,因为vehicle_id是复合主键吗? 请帮忙!!

1 个答案:

答案 0 :(得分:2)

您需要在$i = 0; //Forming data array while( $i < 3) { $data_array .= "{ "; $data_array .= "'customIcon': new google.maps.MarkerImage('" . $marker_image . "', null, null, null, new google.maps.Size(50, 69)), "; $data_array .= "'latLng': new google.maps.LatLng(" . $coordinate[0] . ", " . $coordinate[1] . "), "; $data_array .= "'postId':'" . get_the_ID() . "', "; $data_array .= "'postType': 'red', "; $data_array .= "'alreadyLoaded': false, "; $data_array .= " }," . "\n"; $i++; } //Response $response = array(); array_push ( $response, $results_html, $data_array, $count ); echo json_encode( $response ); //In ajax success: console.log( [response[1]] ); //It should have 4 items but it's containing only 1 item that is single long string from all 4 object //I'll get Google Map error: Uncaught TypeError: Cannot read property 'lat' of undefined 表中添加PlateNo列并在其上定义外键。

tbl_Customer_Vehicle