You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@phoenix.apache.org by Mariana Medeiros <63...@gmail.com> on 2016/05/12 11:24:12 UTC

FOREIGN KEY

Hello,

Do you know how to create an HBase table with no primary key and with a
foreign key?

Something like:

(TABLE) CUSTOMER:
CustomerID (pk)
CustomerName


(TABLE) TELEPHONE:
CustomerID (fk)
TelephoneType
TelephoneNumber


How to create a telephone table like that?

Thank you.

Re: FOREIGN KEY

Posted by Steve Terrell <st...@oculus360.us>.
If you don't have any unique data, you could use a Phoenix Sequence
<https://phoenix.apache.org/sequences.html> to generate keys as you upsert.
 or some kind of guid.

On Thu, May 12, 2016 at 8:22 AM, Ciureanu Constantin <
ciureanu.constantin@gmail.com> wrote:

> CREATE TABLE IF NOT EXISTS TELEPHONE (
> CustomerID INT,
> TelephoneType VARCHAR,
> TelephoneNumber VARCHAR
> CONSTRAINT PK PRIMARY KEY (CustomerID, TelephoneType)
> );
>
> In case it's still not unique, add the TelephoneNumber too.
>
> ...
> CONSTRAINT PK PRIMARY KEY (CustomerID, TelephoneType, TelephoneNumber )
>
>
> 2016-05-12 15:14 GMT+02:00 Ciureanu Constantin <
> ciureanu.constantin@gmail.com>:
>
>> Just create a new first unique field CustomerID + TelephoneType to play
>> the PK role, something has to be unique there and a HBase table needs a Key
>> (this concatenation of 2 or more values is valid in case it's unique
>> otherwise invent some other 3rd part or risk to lose phone numbers that are
>> "duplicates" - eg. for the same CustomerID and Type).
>>
>> 2016-05-12 13:24 GMT+02:00 Mariana Medeiros <63...@gmail.com>:
>>
>>> Hello,
>>>
>>> Do you know how to create an HBase table with no primary key and with a
>>> foreign key?
>>>
>>> Something like:
>>>
>>> (TABLE) CUSTOMER:
>>> CustomerID (pk)
>>> CustomerName
>>>
>>>
>>> (TABLE) TELEPHONE:
>>> CustomerID (fk)
>>> TelephoneType
>>> TelephoneNumber
>>>
>>>
>>> How to create a telephone table like that?
>>>
>>> Thank you.
>>>
>>
>>
>

Re: FOREIGN KEY

Posted by Ciureanu Constantin <ci...@gmail.com>.
CREATE TABLE IF NOT EXISTS TELEPHONE (
CustomerID INT,
TelephoneType VARCHAR,
TelephoneNumber VARCHAR
CONSTRAINT PK PRIMARY KEY (CustomerID, TelephoneType)
);

In case it's still not unique, add the TelephoneNumber too.

...
CONSTRAINT PK PRIMARY KEY (CustomerID, TelephoneType, TelephoneNumber )

2016-05-12 15:14 GMT+02:00 Ciureanu Constantin <
ciureanu.constantin@gmail.com>:

> Just create a new first unique field CustomerID + TelephoneType to play
> the PK role, something has to be unique there and a HBase table needs a Key
> (this concatenation of 2 or more values is valid in case it's unique
> otherwise invent some other 3rd part or risk to lose phone numbers that are
> "duplicates" - eg. for the same CustomerID and Type).
>
> 2016-05-12 13:24 GMT+02:00 Mariana Medeiros <63...@gmail.com>:
>
>> Hello,
>>
>> Do you know how to create an HBase table with no primary key and with a
>> foreign key?
>>
>> Something like:
>>
>> (TABLE) CUSTOMER:
>> CustomerID (pk)
>> CustomerName
>>
>>
>> (TABLE) TELEPHONE:
>> CustomerID (fk)
>> TelephoneType
>> TelephoneNumber
>>
>>
>> How to create a telephone table like that?
>>
>> Thank you.
>>
>
>

Re: FOREIGN KEY

Posted by Ciureanu Constantin <ci...@gmail.com>.
Just create a new first unique field CustomerID + TelephoneType to play the
PK role, something has to be unique there and a HBase table needs a Key
(this concatenation of 2 or more values is valid in case it's unique
otherwise invent some other 3rd part or risk to lose phone numbers that are
"duplicates" - eg. for the same CustomerID and Type).

2016-05-12 13:24 GMT+02:00 Mariana Medeiros <63...@gmail.com>:

> Hello,
>
> Do you know how to create an HBase table with no primary key and with a
> foreign key?
>
> Something like:
>
> (TABLE) CUSTOMER:
> CustomerID (pk)
> CustomerName
>
>
> (TABLE) TELEPHONE:
> CustomerID (fk)
> TelephoneType
> TelephoneNumber
>
>
> How to create a telephone table like that?
>
> Thank you.
>