# How do you handle \< 1 Schema for a database?

**URL:** <https://forum.xojo.com/t/how-do-you-handle-1-schema-for-a-database/80108>\
**Category:** Databases\
**Created:** [April 25, 2024, 12:59am UTC](https://forum.xojo.com/t/how-do-you-handle-1-schema-for-a-database/80108 "2024-04-25T00:59:47Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tim\_Seyfarth](https://forum.xojo.com/letter_avatar_proxy/v4/letter/t/d26b3c/32.png) [@Tim\_Seyfarth](https://forum.xojo.com/u/Tim_Seyfarth)\
**Post date:** [April 25, 2024, 12:59am UTC](https://forum.xojo.com/t/how-do-you-handle-1-schema-for-a-database/80108/1 "2024-04-25T00:59:47Z")

</div>

Hello all,

In code, how do you handle \< 1 schemas in the same database? Say there us the Public Schema then there is another one Schema2. How to read and write to #2.

Or is that a really bad idea?

I am asking bc I have a db that has all of the tables necessary for one application. I need to either add more tables to suit another app, use another schema OR create another database.

This is for a set of web apps that will be hosted, possibly by Xojo (not sure yet).

Thanks,  
Tim

---

<div class="post-metadata">

**Author:** ![Beatrix\_Willius](https://forum.xojo.com/user_avatar/forum.xojo.com/beatrix_willius/32/282_2.png) [@Beatrix\_Willius](https://forum.xojo.com/u/Beatrix_Willius)\
**Post date:** [April 25, 2024, 1:20am UTC](https://forum.xojo.com/t/how-do-you-handle-1-schema-for-a-database/80108/2 "2024-04-25T01:20:17Z")

</div>

What do you mean with smaller than one schemas? And the you say you have multiple schemata. There is only one database schema and your main app may use only a part of it.

---

<div class="post-metadata">

**Author:** ![Tim\_Parnell](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_parnell/32/161_2.png) [@Tim\_Parnell](https://forum.xojo.com/u/Tim_Parnell)\
**Post date:** [April 25, 2024, 3:20pm UTC](https://forum.xojo.com/t/how-do-you-handle-1-schema-for-a-database/80108/3 "2024-04-25T15:20:51Z")

</div>

Beatrix, I think OP got greater than and less than backwards.

Tim, I generally have two functions in my database apps for helping with schemas. A function for `HasTable(extends db as Database, sTable as String) as Boolean` and a function for `TableHasColumn(extends db as Database, sTable as String, sColumn as String) as Boolean`.

They’re shortcuts because the framework will only list all tables in the database or all columns on a table, so these functions just help me find what I’m looking for. You might be able to do something similar, and then in your second app that needs additional tables you could look for them and create them if necessary.

Edit: (It’s basically the [sample code from here](https://documentation.xojo.com/api/databases/database.html#database-tables) that returns true instead of using MsgBox)

If you find my advice useful, you should check out [Lifeboat](https://strawberrysw.com/lifeboat) for deploying your Web Apps. I tend to go out of my way to help my customers with web app questions on the forum 😉

---

<div class="post-metadata">

**Author:** ![Tim\_Seyfarth](https://forum.xojo.com/letter_avatar_proxy/v4/letter/t/d26b3c/32.png) [@Tim\_Seyfarth](https://forum.xojo.com/u/Tim_Seyfarth)\
**Post date:** [April 25, 2024, 7:27pm UTC](https://forum.xojo.com/t/how-do-you-handle-1-schema-for-a-database/80108/4 "2024-04-25T19:27:35Z")

</div>

> [@Tim\_Parnell](#):
>
> Beatrix, I think OP got greater than and less than backwards.

Yes Tim, you are correct.

For lifeboat, I have the trial edition. Once I get further, I am sure I will be using it!  
Thank you,  
Tim

---

<div class="post-metadata">

**Author:** ![Tim\_Hare](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_hare/32/176_2.png) [@Tim\_Hare](https://forum.xojo.com/u/Tim_Hare)\
**Post date:** [April 26, 2024, 12:59am UTC](https://forum.xojo.com/t/how-do-you-handle-1-schema-for-a-database/80108/5 "2024-04-26T00:59:54Z")

</div>

Do the schemas overlap? Ie., does the second app use some of the same data as the first app? And is that data shared? Or does each app need a separate set of data?

---

<div class="post-metadata">

**Author:** ![Tim\_Seyfarth](https://forum.xojo.com/letter_avatar_proxy/v4/letter/t/d26b3c/32.png) [@Tim\_Seyfarth](https://forum.xojo.com/u/Tim_Seyfarth)\
**Post date:** [April 26, 2024, 6:30pm UTC](https://forum.xojo.com/t/how-do-you-handle-1-schema-for-a-database/80108/6 "2024-04-26T18:30:58Z")

</div>

Hi Tim,  
I expect there to be some overlap.

But in light of what appears to be a much higher degree of complexity, I think I will either use the Public schema or create a new database.

Tim

---

<div class="post-metadata">

**Author:** ![Jean-Yves\_Pochez](https://forum.xojo.com/user_avatar/forum.xojo.com/jean-yves_pochez/32/21769_2.png) [@Jean-Yves\_Pochez](https://forum.xojo.com/u/Jean-Yves_Pochez)\
**Post date:** [April 26, 2024, 6:54pm UTC](https://forum.xojo.com/t/how-do-you-handle-1-schema-for-a-database/80108/7 "2024-04-26T18:54:05Z")

</div>

I have an app that has 2 databases it can access.  
the user chooses at startup if he wants to use the production or the test database  
then the app use the choosed database.  
quite easy to make, just open two databases connexions, and use the one you need.  
in my case, as I use only one database at a time, I open only one database at startup.

on another app, I open two postgres databases, but published on two different tcp ports.  
so again I have two properties opened at startup, and I use both during the app  
some datas are in one database, and other datas in the other database  
invoices and customers are in one database, and accounting data in the other.
