1. Roger
  2. as Valentina DB Server
  3. 火, 8月 04 2020, 04:43 PM
  4.  メールで購読
Hello

When I have an existing db with 2 tables person - phones. In relation 1:n (a phone can have only 1 user in this example). In this db the conection is with primary keys, comun. So far so good.

Now, if I try with Valentina and the idea from Recid and Link. How can I do this? Write the primary key to the RecId I think is not the concept.... But how know the Valkentina db what are the phones from a person? I have not found in the helps.

Reghards Roger
コメント
There are no comments made yet.
Sergey Pashkov 承諾済みの回答
Hello Roger,

ObjectPtr LINK is alternative to Primary Key+Foreign Key scheme.
I attached a link to article which describes ObjectPtr.

Here's an example database:

CREATE TABLE "Person"(
"FirstName" VARCHAR ( 2044 ) );

CREATE TABLE "Phone"(
"Number" VARCHAR ( 2044 ),
"Person_ptr" OBJECTPTR CONSTRAINT "lnk_Person_Phone"
REFERENCES "Person"
ON DELETE RESTRICT INDEXED );

INSERT INTO "Person" ("FirstName") VALUES ('Robert');
INSERT INTO "Person" ("FirstName") VALUES ('Brian');
INSERT INTO "Person" ("FirstName") VALUES ('John');
INSERT INTO "Person" ("FirstName") VALUES ('Peter');

INSERT INTO "Phone" ("Number", "Person_ptr") VALUES ('1111', 1);
INSERT INTO "Phone" ("Number", "Person_ptr") VALUES ('2222', 3);
INSERT INTO "Phone" ("Number", "Person_ptr") VALUES ('3333', 1);
INSERT INTO "Phone" ("Number", "Person_ptr") VALUES ('4444', 2);
INSERT INTO "Phone" ("Number", "Person_ptr") VALUES ('5555', NULL);
INSERT INTO "Phone" ("Number", "Person_ptr") VALUES ('6666', NULL);


A few examples of JOIN queries on this link:

-- Ordinary JOIN
SELECT * FROM Person JOIN Phone ON Person.RecID = Phone.Person_ptr;

-- JOIN ON link
SELECT * FROM Person JOIN Phone ON lnk_Person_Phone;

-- There is only one link, so no need to specify it
SELECT * FROM Person JOIN Phone;

-- Operator -> on ObjectPtr field Person_ptr allows writing queries even without JOIN
SELECT Person_ptr->FirstName, Number FROM Phone;
参照
  1. http://valentina-db.com/docs/dokuwiki/v10/doku.php?id=valentina:vcomponents:vkernel:vlink:objectptr
コメント
There are no comments made yet.
Roger 承諾済みの回答
Many thanks Sergey, now its clear.

have a nice day
Roger
コメント
There are no comments made yet.
Ruslan Zasukhin 承諾済みの回答
コメント
There are no comments made yet.
Roger 承諾済みの回答
Thanks Ruslan, with link and pointer it works fine. About binary links I have read but not tried.

LINK RECORD (1) OF Person TO RECORD (3) OF Phone;

Is (1) and (3) the RecID from a Record and a sql command LINK make the connection (defined bevore as b9nsy link)?
コメント
There are no comments made yet.
  • ページ :
  • 1


There are no replies made for this post yet.
However, you are not allowed to reply to this post.