# Relational Database Inserts

**URL:** <https://forum.kirupa.com/t/relational-database-inserts/235777>\
**Category:** programming\
**Created:** [August 14, 2007, 5:39pm UTC](https://forum.kirupa.com/t/relational-database-inserts/235777 "2007-08-14T17:39:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![evildrummer](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/evildrummer/32/2308_2.png) [@evildrummer](https://forum.kirupa.com/u/evildrummer)\
**Post date:** [August 14, 2007, 5:39pm UTC](https://forum.kirupa.com/t/relational-database-inserts/235777/1 "2007-08-14T17:39:31Z")

</div>

For a new project of mine I have used two tables that are tightly linked (sadly I can’t show you the tables as its confidential [even column titles]) Any way my queries for getting stuff look like this:

```auto

SELECT b.column FROM table_one a, table_two b WHERE b.foreign_key = a.primary_key AND a.column = something

```

But how would I do an insert like this? The problem I am having is both tables have a primary key, but table\_two also has a foreign key (the primary key of table\_one) But when I insert data how do I get it so it inserts into both tables but automatically has table\_twos foreign key thing set to the equivalent row in table\_one.
