# Periodic Table Database

**URL:** <https://forum.freecodecamp.org/t/periodic-table-database/550158>\
**Category:** Curriculum Help\
**Tags:** backend\
**Created:** [September 2, 2022, 11:28am UTC](https://forum.freecodecamp.org/t/periodic-table-database/550158 "2022-09-02T11:28:07Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Msaligs](https://avatars.discourse-cdn.com/v4/letter/m/ed655f/32.png) [@Msaligs](https://forum.freecodecamp.org/u/Msaligs)\
**Post date:** [September 2, 2022, 11:28am UTC](https://forum.freecodecamp.org/t/periodic-table-database/550158/1 "2022-09-02T11:28:07Z")

</div>

I have a doubt on the following points

> 1: Your properties table should have a `type_id` foreign key column that references the `type_id` column from the `types` table. It should be an INT with the NOT NULL constraint

I used the query

```auto
alter table properties add column type_id int not null references types(type_id);

```

it shows me some error about null values, so I break the problem into mini problems as

- add the column `type_id` to the table `properties`
- insert the values manually one by one into each cell of `type_id` column (boring task)
- add the constraint `NOT NULL ` to column `type_id`
- make it `foreign key` with reference from `types(type)`

> Q: since the table has only few rows of data i completed the task in few minutes, and I don`t think it is a feasible solution.  
> what`s the correct way to do it?

> 2:The schema of the 3 tables is as
> 
> ![image](https://global.discourse-cdn.com/freecodecamp/original/4X/e/f/2/ef24e06bec26719293739932425deb174b86d586.png)

 ![image](https://global.discourse-cdn.com/freecodecamp/original/4X/7/0/5/70504ca68c947bef84490f50870eac5832ce211f.png)

 ![image](https://global.discourse-cdn.com/freecodecamp/original/4X/d/2/5/d253766b074f328e3c7da63b9865080c7662e1f1.png)

the data given to enter into tables is

 ![image](https://global.discourse-cdn.com/freecodecamp/original/4X/6/4/6/6466ad70456fd72fe96a1f77da9662c24194c896.png)

> Q : Is it possible to enter data into all three tables simultaneously using single query or I have to enter the data separately specific to that table?

---

<div class="post-metadata">

**Author:** ![ihsotaS](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ihsotas/32/274410_2.png) [@ihsotaS](https://forum.freecodecamp.org/u/ihsotaS)\
**Post date:** [September 6, 2022, 10:45pm UTC](https://forum.freecodecamp.org/t/periodic-table-database/550158/2 "2022-09-06T22:45:48Z")

</div>

Im sticking around since i have a similar doubt but for this question:

> Your `properties` table should have a `type_id` foreign key column that references the `type_id` column from the `types` table. It should be an `INT` with the `NOT NULL` constraint

I wonder if there’s a way to make the reference to the other table and automatically fill in this values with the type\_id of the types table.

---

<div class="post-metadata">

**Author:** ![kwame.arms](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/kwame.arms/32/281044_2.png) [@kwame.arms](https://forum.freecodecamp.org/u/kwame.arms)\
**Post date:** [September 8, 2022, 3:45am UTC](https://forum.freecodecamp.org/t/periodic-table-database/550158/3 "2022-09-08T03:45:58Z")

</div>

> [@Msaligs](#):
>
> Your properties table should have a `type_id` foreign key column that references the `type_id` column from the `types` table. It should be an INT with the NOT NULL constraint

About this part: it doesn’t need to be completed in one command. The way I resolved it was to add the column to the properties table, then fill it with data using UPDATE. Lastly, I added the NOT NULL constraint and the foreign key.

> [@Msaligs](#):
>
> Q : Is it possible to enter data into all three tables simultaneously using single query or I have to enter the data separately specific to that table?

You can enter data into multiple columns with one command, but I don’t believe this is true for multiple tables.

---

<div class="post-metadata">

**Author:** ![Msaligs](https://avatars.discourse-cdn.com/v4/letter/m/ed655f/32.png) [@Msaligs](https://forum.freecodecamp.org/u/Msaligs)\
**Post date:** [September 8, 2022, 8:24am UTC](https://forum.freecodecamp.org/t/periodic-table-database/550158/4 "2022-09-08T08:24:28Z")

</div>

@zaira_h can you please help?

---

<div class="post-metadata">

**Author:** ![ihsotaS](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ihsotas/32/274410_2.png) [@ihsotaS](https://forum.freecodecamp.org/u/ihsotaS)\
**Post date:** [September 8, 2022, 9:29am UTC](https://forum.freecodecamp.org/t/periodic-table-database/550158/5 "2022-09-08T09:29:12Z")

</div>

Thanks for the reply, i know question does not need to be completed in one step and I indeed completed the way you said but I was wondering if there was a more optimal way to solve this question.

---

<div class="post-metadata">

**Author:** ![zaira\_h](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/zaira_h/32/259593_2.png) [@zaira\_h](https://forum.freecodecamp.org/u/zaira_h)\
**Post date:** [September 8, 2022, 9:51am UTC](https://forum.freecodecamp.org/t/periodic-table-database/550158/6 "2022-09-08T09:51:18Z")

</div>

Hi, what do you need help with? Yes, you can simultaneously enter data in a table using INSERT.

---

<div class="post-metadata">

**Author:** ![Msaligs](https://avatars.discourse-cdn.com/v4/letter/m/ed655f/32.png) [@Msaligs](https://forum.freecodecamp.org/u/Msaligs)\
**Post date:** [September 8, 2022, 10:37am UTC](https://forum.freecodecamp.org/t/periodic-table-database/550158/7 "2022-09-08T10:37:55Z")

</div>

yeah,we can simultaneously enter data into `1 table` using `INSERT` ,can we enter data simultaneously into more `2 tables`?

---

<div class="post-metadata">

**Author:** ![terrachad](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/terrachad/32/323994_2.png) [@terrachad](https://forum.freecodecamp.org/u/terrachad)\
**Post date:** [April 2, 2023, 2:37pm UTC](https://forum.freecodecamp.org/t/periodic-table-database/550158/8 "2023-04-02T14:37:43Z")

</div>

![image](https://global.discourse-cdn.com/freecodecamp/original/4X/e/0/5/e055f1b919c4c1f27e9ef8c87cd12fbea6108b98.png)

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 7, 2025, 12:02pm UTC](https://forum.freecodecamp.org/t/periodic-table-database/550158/9 "2025-01-07T12:02:16Z")

</div>

Closed on January 7, 2025, 12:02pm UTC


