On INSERT to a table INSERT data in connected tables

Solutions

You might want to read about using Drupal hooks to add extra code to be run when a user is registered. Once you know how to use hooks, you can write code (in a module) to insert a corresponding record in the 2nd table. A good candidate hook to use here would be hook_user for Drupal 6 or hook_user_insert for Drupal 7.

The REFERENCES you read about is part of an SQL command to define a foreign key constraint from the second table to the first. This is not strictly necessary to solve your problem, but it can help in keeping your database consistent. I suggest you read up on database structures and constraints if you want to learn more on this topic.

pgAdmin is just the GUI. You mean PostgreSQL, the RDBMS.

A foreign key constraint, like you have only enforces that no value can be used, that isn't present in the referenced column. You can use ON UPDATE CASCADE or ON DELETE CASCADE to propagate changes from the referenced column, but you cannot create new rows with it like you describe. You got the wrong tool.

What you describe could be achieved with a trigger. Another, more complex way would be a RULE. Go with a trigger here.

In PostgreSQL you need a trigger function, mostly using plpgsql, and a trigger on a table that makes use of it.

Something like:

CREATE OR REPLACE FUNCTION trg_insert_row_in_tbl2()
  RETURNS trigger AS
$func$
BEGIN
   INSERT INTO tbl2 (my_id, col1)
   VALUES (NEW.my_id, NEW.col1)     -- more columns?

   RETURN NEW;  -- doesn't matter much for AFTER trigger
END
$func$  LANGUAGE plpgsql;

And a trigger AFTER INSERT on tbl1:

CREATE TRIGGER insaft
AFTER INSERT ON tbl1
FOR EACH ROW EXECUTE PROCEDURE trg_insert_row_in_tbl2();

Similar questions

View of taxonomies connected to view of each taxonomy
I'm creating a store using Drupal commerce and I'm trying to show a catalog of products. I want to show all products of a type every time I click on a taxonomy in product type catalog view. Can anyone help me?
How to control the display of a user account connected via entity reference
My searches have turned up nothing, I'm sure it is something simple but I can't figure it out. To give a simple version of my set up: I have a content type for publications, that publication has a paragraph field for authors. That paragraph field accepts either a user linked by entity reference, or a non-user author (a set of text fields). My end g...
how theme/template connected/related to each other
for example, I have: and inside my field formatter: with function: as simple as: with that, seems like i can't see my template, which i don't have any idea why? how is theme or template name relate with the filename (or ID or anything)? - how are they connected each other? what is the rule for that? Thank you, AnD
How can I get a list of all connected/logged in users?
I would like to make a list of all logged in users accessible through the backend. The routes are created. It is only the request to retrieve the users that I would need. Is this data in the 'sessions' table? Thank you in advance for your help
After insert data to table, updating data in home page drupal7
I have a insert_data module that used to insert data to category table, and I also have a module named mysite that has a function named “function mysite_preprocess_panels_pane(&$variables) “ is used to render data to panel.tbl.php. My question is how can I call function “mysite_preprocess_panels_pane(&$variables)” from mysite module. My pur...
How to insert data into node and other tables at the same time?
I create a Drupal module which install database tables during module installation, table is created using Drupal way. The tables are created perfectly and now i have to insert data into those tables. Example table structure where i want data to be inserted in sequence : Once data are inserted into database, the site admin will retrieve those saved ...

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.